Install the docker and Docker Distribution packages. These packages are found in the Extras repo.
yum install -y docker docker-distributionEnable and start Docker and Docker Distribution.
systemctl enable dockersystemctl enable docker-distributionsystemctl start dockersystemctl start docker-distributionConfiguration
STORAGE
To change the location of the stored docker images amend the rootdirectory config setting in /etc/docker-distribution/registry/config.yml.
vim /etc/docker-distribution/registry/config.ymlrootdirectory: /var/lib/registryHTTPS/TLS
Create a self signed certificate or purchase a certificate from a trusted CA.
mkdir /certs/cd /certs/openssl req -newkey rsa:4096 -nodes -sha256 -keyout server.key -x509 -days 365 -out server.crtCopy the keys into /etc/docker/certs.d/
cp server.crt server.key /etc/docker/certs.d/.Edit the registry configuration file and add the following under http.
vim /etc/docker-distribution/registry/config.ymlhttp: addr: 192.168.0.1:5000 tls: certificate: /etc/docker/certs.d/server.crt key: /etc/docker/certs.d/server.keyAuhentication
There are several methods for authentication but we will use a htpasswd file.
Install httpd-tools
yum install httpd-toolsCreate the htpasswd file
mkdir /etc/docker-distribution/registry/authchmod 750 /etc/docker-distribution/registry/authhtpasswd -Bc /etc/docker-distribution/registry/auth/registery_users user_nameEdit the registry configuration file and add the following under Auth.
vim /etc/docker-distribution/registry/config.ymlauth: htpasswd: realm: basic-realm path: /etc/docker-distribution/registry/auth/registery_usersUsing the Docker Registry
Pull an image from a remote registry.
docker pull registry.access.redhat.com/rhel7/rhelList images in Docker
docker imagesLoad a tarball image into Docker
docker load -i rhel-server-docker-7.2.x86_64.tar.gzTo push an image into your local repository you need to tag it with your registry information first.
docker tag bef54b8f8a2f localhost:5000/docker_imagedocker push localhost:5000/docker_imageRun a quick command
docker run -v /usr/sbin:/usr/bin --rm rhel /usr/sbin/ip addr show eth0# -v Mount host directory to make it available to the container
# --rm Remove the container after execution of the command
docker run -v /usr/sbin:/usr/sbin --name=myipaddr rhel /usr/sbin/ip addr show eth0# --name Names the container so it can be started again by name next time.
docker start -i myipaddr# -i Attach container's STDIN
View the docker file in the container
docker run --rm localhost:5000/rhel7 ls /root/buildinfoRun a shell inside the container. From here you can use yum and other commands
docker run --name=mybash -it rhel /bin/bashShow containers
docker ps -aBind mount log files. This makes the containers messages available to the host
docker run --rm --name=test_log3 -v /dev/log:/dev/log server2.grow4.co.uk:5000/rhel7 logger "Testing logging to the host"List containers
docker ps # Runninig containersdocker ps -a # All containersInspect the metadata of an existing container
docker inspectdocker inspect --format='{{.NetworkSettings.Networks.bridge.IPPrefixLen}}' 8bfde4062140Investigating within a running Docker container
docker exec will run a command in a container without interrupting the application the container is running.
docker exec -it myrhel_httpd /bin/bashIf you ran a container, but didn’t remove it (--rm), that container is stored on your local system and ready to run again. To start a previously run container that wasn’t removed, use the start option. To stop a running container, use the stop option
Start a non-interactive user
docker start container_nameStart an interactive container
docker start -a -i container_name# -a attache# -i interactiveStopping containers
docker stop container_namedocker kill --signul="SIGHUP"Removing containers
docker rm container_namedocker rm container_name1 container_name2# Remove all containersdocker rm $(docker ps -aq)