I have a lot of images on DockerHub, but I've wanted to download and launch my own Docker image in my Registry at any time.
You can prepare a Dockerfile and create it from the Docker image downloaded from DockerHub, but it takes a surprising amount of time, so I'd like to prepare an image in a ready state and put it on some Docker server.
Communication with certificate registration via HTTPS is also possible, but this is just a method of preparing an environment that can be used quickly for internal use.
Have two environments (such as VMs) on the server and client.
Roughly the following steps
Must be installed on the Redistry server and client side. Download destination registration is required to install docker to rpm.
yum -y install yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
Start the docker service on the Redistry server and client side, and start it automatically when the OS starts.
systemctl start docker
systemctl enable docker
Download the Registry image on the Registry server
docker pull registry
Docker image is added as below
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 2d4f4b5309b1 3 months ago 26.2MB
Start Docker Registry. At this time, since we want to make the image on the Registry persistent, mount the directory of the host OS in the container.
docker run -d -p 5000:5000 \
-v /var/opt:/var/lib/registry \
registry
Confirm that the container has started
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35b3882b8536 registry "/entrypoint.sh /etc…" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp dreamy_roentgen
The following directory is created in the host OS and mounted under this directory.
ls /var/opt/docker/registry/v2/
blobs repositories
When the image is registered, it is the directory where the image is saved under repositories as shown below.
ls -l /var/opt/docker/registry/v2/repositories/aaa
Total 0
drwxr-xr-x 5 root root 55 September 16 15:33 centos_local
Anything is fine, but download CentOS for the time being
docker pull centos
Using default tag: latest
latest: Pulling from library/centos
3c72a8ed6814: Pull complete
Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685fbd
Confirm that it was downloaded
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0d120b6ccaa8 5 weeks ago 215MB
registry latest 2d4f4b5309b1 2 months ago 26.2MB
Originally, I used Dockerfile etc. to create an image with various tools and settings, but this time I simply use the downloaded CentOS image as it is
docker tag centos localhost:5000/aaa/centos_local:1.0
If you tag it, you can create an image like the one below.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0d120b6ccaa8 5 weeks ago 215MB
localhost:5000/aaa/centos_local 1.0 0d120b6ccaa8 5 weeks ago 215MB
registry latest 2d4f4b5309b1 2 months ago 26.2MB
Register tagged images in docker Registry
docker push localhost:5000/aaa/centos_local:1.0
The push refers to repository [localhost:5000/iseki/centos_local]
291f6e44771a: Pushed
1.0: digest: sha256:fc4a234b91cc4b542bac8a6ad23b2ddcee60ae68fc4dbd4a52efb5f1b0baad71 size: 529
After registration, the image is no longer needed and will be deleted
docker rmi localhost:5000/iseki/centos_local:1.0
Untagged: localhost:5000/iseki/centos_local:1.0
Untagged: localhost:5000/iseki/centos_local@sha256:fc4a234b91cc4b542bac8a6ad23b2ddcee60ae68fc4dbd4a52efb5f1b0baad71
After deleting, check that there are no images in the list
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0d120b6ccaa8 5 weeks ago 215MB
registry latest 2d4f4b5309b1 2 months ago 26.2MB
You can download it from the server by executing the following command
docker pull localhost:5000/aaa/centos_local:1.0
From the client side, you cannot connect unless you enter the following settings in the "client side"
cat /etc/docker/daemon.json
{ "insecure-registries":["<Docker Registry server IP or host name>:5000"] }
Make the above settings and restart the docker service
systemctl restart docker
In this state, execute the command to get the image from the docker Registroy server.
docker pull 10.1.5.25:5000/aaa/centos_local:1.0
1.0: Pulling from iseki/centos_local
3c72a8ed6814: Pull complete
Digest: sha256:fc4a234b91cc4b542bac8a6ad23b2ddcee60ae68fc4dbd4a52efb5f1b0baad71
Status: Downloaded newer image for 10.1.5.25:5000/aaa/centos_local:1.0
10.1.5.25:5000/aaa/centos_local:1.0
docker image is downloaded
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.1.5.25:5000/aaa/centos_local 1.0 0d120b6ccaa8 7 weeks ago 215MB
Recommended Posts