Installing docker on CentOS 7

First you need to set the repository doing a

yum install -y yum-utils

Then:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

to add the stable Docker repository.

then you can install docker

yum install docker-ce docker-ce-cli containerd.io

Remeber to start the new service with

systemctl start docker

and enable it upon OS reboot

systemctl enable docker

To get the running containers on docker simply type:

docker stats

to stop a container

docker stop <containername>

to start a container upon reboot

docker run -d --restart unless-stopped <containername>

the restart policies are

no Do not automatically restart the container. (the default)
on-failure Restart the container if it exits due to an error, which manifests as a non-zero exit code.
always Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.
unless-stopped Similar to always, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts.

 

 

 

HTTP proxy configuration for Docker on CentOS 7

On CentOS7 if docker is behind a proxy server then use following steps:

  1. Create folder for configuring docker service through systemd
    mkdir /etc/systemd/system/docker.service.d
  2. Create service configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf
    [Service]
    Environment="HTTP_PROXY=http://10.10.6.9:3128/" 
    "NO_PROXY=localhost,127.0.0.0/8,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12"
  3. Reload systemctl so that new settings are read
    systemctl daemon-reload
  4. Verify that docker service Environment is properly set
    systemctl show docker --property Environment
  5. Restart docker service so that it uses updated Environment settings
    systemctl restart docker