Docker 1.11 installation and run on CentOS7:
configure and use the local repository:
Docker registry should be run with the TLS and other security enabled.
This only talks on having the local registry up for use leveraging the docker
regsitry container serving the docker registry to be local.
Get
the Docker repo configured for YUM
$ sudo tee
/etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
yum clean all
yum repolist
yum -y install docker-engine
#
Confirm the docker engine RPMs are installed
[root@compute1 ~]# rpm -qa | grep -i
docker
docker-engine-selinux-1.11.2-1.el7.centos.noarch
docker-engine-1.11.2-1.el7.centos.x86_64
[root@compute1 ~]#
Start
the docker service and optionally enable the autostart.
systemctl start docker.service
systemctl status docker.service
systemctl enable docker.service
##
Check if the docker service is working fine
Try pulling any image from docker
registry and run
docker -it run centos:latest
"/bin/bash"
#
download the latest image for registry from the docker hub (you can pull and
run or can directly run as the run will pull it for the first time from the
docker hub)
docker
pull registry
[root@compute1 yum.repos.d]# docker
pull registry
Using default tag: latest
latest: Pulling from library/registry
8387d9ff0016: Pull complete
3b52deaaf0ed: Pull complete
4bd501fad6de: Pull complete
a3ed95caeb02: Pull complete
1d4dc7bffbb8: Pull complete
7c4baf947271: Pull complete
e14b922ad4f5: Pull complete
f1d1dbdd4f97: Pull complete
f2bbca3948d0: Pull complete
4e3899dc28fa: Pull complete
Digest:
sha256:f374c0d9b59e6fdf9f8922d59e946b05fbeabaed70b0639d7b6b524f3299e87b
Status: Downloaded newer image for
registry:latest
#
See all the downloaded docker images
[root@compute1 yum.repos.d]# docker
images
REPOSITORY
TAG IMAGE ID
CREATED
SIZE
centos
latest
50dae1ee8677 Less than a second ago
196.7 MB
registry
2
8ff6a4aae657 4 weeks ago
171.5 MB
registry
latest
bca04f698ba8 5 months ago
422.8 MB
[root@compute1 yum.repos.d]#
#
Start of the docker container for the registry, we will start with the option
as restart always.
docker run -d -p 5000:5000
--restart=always --name=localregistry registry:2
#
confirm that the registry container is up
docker ps
[root@compute1 yum.repos.d]# docker ps
CONTAINER ID
IMAGE COMMAND
CREATED
STATUS
PORTS
NAMES
01057f771545
registry:2 "/bin/registry serve
" 12 minutes ago Up 12 minutes
0.0.0.0:5000->5000/tcp localregistry
[root@compute1 yum.repos.d]#
#
push the CentOS image to the local registry
#
tag the image first to be pushed to the local registry
docker tag centos
localhost:5000/centos
#
confirm the tag has been given
docker images
[root@compute1 yum.repos.d]# docker
images
REPOSITORY
TAG
IMAGE ID CREATED
SIZE
centos
latest
50dae1ee8677 Less than a second ago
196.7 MB
localhost:5000/centos latest
50dae1ee8677
Less than a second ago 196.7 MB
registry
2
8ff6a4aae657 4 weeks ago
171.5 MB
registry
latest
bca04f698ba8 5 months ago
422.8 MB
[root@compute1 yum.repos.d]#
#
upload the tagged image now to local image repository
docker push localhost:5000/centos
[root@compute1 yum.repos.d]# docker
push localhost:5000/centos
The push refers to a repository
[localhost:5000/centos]
0fe55794a0f7: Pushed
latest: digest:
sha256:e513d34ffa01c803fc812a479303fe0a4c14673f84301b877bec060578865f1b size:
529
#
you can see that the push happens to the local repository reference
# Pull the image from the local
repository
docker pull localhost:5000/centos
[root@compute1 yum.repos.d]# docker
push localhost:5000/centos
The push refers to a repository
[localhost:5000/centos]
0fe55794a0f7: Layer already exists
latest: digest:
sha256:7b754086d2c7d74ac39dc0a2545d7b06d4266f873d502feb5b3e8bfca27c5dd8 size:
507
[root@compute1 yum.repos.d]#
As this images is already there in the
local repo it says already present
#
Start the container with the image which you have in the local registry
docker run localhost:5000/centos
"/bin/bash" -it
#
Lets make some changes inside the container, I will install httpd in there from
the CENTOS repos
[root@compute1 yum.repos.d]# docker
run -it localhost:5000/centos "/bin/bash"
[root@dc110984e8f0 /]#
[root@dc110984e8f0 /]#
[root@dc110984e8f0 /]# yum install
httpd
[root@dc110984e8f0 etc]# rpm -qa |
grep -i http
httpd-tools-2.4.6-40.el7.centos.4.x86_64
httpd-2.4.6-40.el7.centos.4.x86_64
[root@dc110984e8f0 etc]#
[root@dc110984e8f0 etc]#
[root@dc110984e8f0 etc]#
#
open another session to the docker host and commit on the running container
after the installation of httpd
# from other terminal
docker ps
[root@compute1 ~]# docker ps
CONTAINER ID
IMAGE COMMAND
CREATED
STATUS
PORTS
NAMES
8c5bcba48f2d
localhost:5000/centos "/bin/bash"
3 minutes ago Up 3 minutes
distracted_blackwell
01057f771545
registry:2
"/bin/registry serve " 38 minutes ago
Up 38 minutes 0.0.0.0:5000->5000/tcp
localregistry
[root@compute1 ~]#
#
Commit the changes to the container image (install of HTTP is a change to the base
image of the container). Committing saves the current state of the container
into a new image with the changes. Also the changes are in the form of layered
FS on top of the base layer.
[root@compute1 ~]# docker commit
8c5bcba48f2d localhost:5000/centos_with_test_http_install
sha256:9e047acbf61557af27e84054042d8d6f4d58202b9c27db8b9372c49e41d81892
[root@compute1 ~]#
[root@compute1 ~]#
[root@compute1 ~]#
#
confirm this is seen as an image
docker images
[root@compute1 ~]# docker images
REPOSITORY
TAG
IMAGE ID CREATED
SIZE
centos
latest
50dae1ee8677 Less than a second ago
196.7 MB
localhost:5000/centos
latest 50dae1ee8677
Less than a second ago 196.7 MB
localhost:5000/centos_with_test_http_install
latest 9e047acbf615
54 seconds ago
316.8 MB
registry
2
8ff6a4aae657 4 weeks ago
171.5 MB
registry
latest
bca04f698ba8 5 months ago
422.8 MB
[root@compute1 ~]#
#
stop the container and delete the images localhost:5000/centos
This
deletes the base image as we plan to use the image which we have installed
HTTPD on the base image.
[root@compute1 ~]# docker ps
CONTAINER ID
IMAGE
COMMAND CREATED
STATUS
PORTS
NAMES
8c5bcba48f2d
localhost:5000/centos "/bin/bash"
12 minutes ago Up 12 minutes
distracted_blackwell
01057f771545
registry:2
"/bin/registry serve " 47 minutes ago
Up 47 minutes 0.0.0.0:5000->5000/tcp
localregistry
#
Stopping the container which is running the CentOS with Apache but has come
from CentOS Local Repository
[root@compute1 ~]# docker stop
8c5bcba48f2d
8c5bcba48f2d
[root@compute1 ~]#
[root@compute1 ~]#
#
Ensure the container is stopped
[root@compute1 ~]# docker ps
CONTAINER ID
IMAGE COMMAND
CREATED
STATUS
PORTS
NAMES
01057f771545
registry:2 "/bin/registry serve
" 47 minutes ago Up 47 minutes
0.0.0.0:5000->5000/tcp localregistry
[root@compute1 ~]#
[root@compute1 ~]#
#
Remove the local image with the name localhost:5000/centos
[root@compute1 ~]# docker images
REPOSITORY
TAG
IMAGE ID CREATED
SIZE
centos
latest
50dae1ee8677 Less than a second ago
196.7 MB
localhost:5000/centos
latest 50dae1ee8677
Less than a second ago 196.7 MB
localhost:5000/centos_with_test_http_install
latest 9e047acbf615
2 minutes ago
316.8 MB
registry
2
8ff6a4aae657 4 weeks ago
171.5 MB
registry
latest
bca04f698ba8 5 months ago
422.8 MB
[root@compute1
~]# docker rmi localhost:5000/centos
Untagged: localhost:5000/centos:latest
[root@compute1 ~]#
[root@compute1 ~]#
#
Ensure the image is gone
[root@compute1 ~]# docker images
REPOSITORY
TAG
IMAGE ID CREATED
SIZE
centos
latest
50dae1ee8677 Less than a second ago
196.7 MB
localhost:5000/centos_with_test_http_install
latest 9e047acbf615
2 minutes ago
316.8 MB
registry
2
8ff6a4aae657 4 weeks ago
171.5 MB
registry
latest
bca04f698ba8 5 months ago
422.8 MB
[root@compute1 ~]#
#
Spin a container from the available image which has the base centos with httpd
installation
[root@compute1 yum.repos.d]# docker
run localhost:5000/centos_with_test_http_install "/bin/bash"
[root@compute1
yum.repos.d]# docker run -it localhost:5000/centos_with_test_http_install
"/bin/bash"
[root@f3bcbb08427a /]#
[root@f3bcbb08427a /]#
[root@f3bcbb08427a /]# rpm -qa | grep
-i http
httpd-tools-2.4.6-40.el7.centos.4.x86_64
httpd-2.4.6-40.el7.centos.4.x86_64
[root@f3bcbb08427a /]#
#
so you can see you have the container with the test apache.