Ensure that your server has proper proxy setup (may be squid or cntlm.service)
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Now install the docker-ce (community additon)
sudo yum install docker-ce
sudo systemctl enable docker
sudo systemctl start docker
During installation you might notice such errors then download mannually and install or retry one more time
===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
docker-ce x86_64 3:19.03.2-3.el7 docker-ce-stable 24 M
Installing for dependencies:
container-selinux noarch 2:2.107-3.el7 prd-rhel-7-extras 39 k
containerd.io x86_64 1.2.6-3.3.el7 docker-ce-stable 26 M
docker-ce-cli x86_64 1:19.03.2-3.el7 docker-ce-stable 39 M
Transaction Summary
===============================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 90 M
Installed size: 368 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): container-selinux-2.107-3.el7.noarch.rpm | 39 kB 00:00:00
containerd.io-1.2.6-3.3.el7.x8 FAILED
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: download. docker.com; Name or service not known"
Trying other mirror.
docker-ce-19.03.2-3.el7.x86_64 FAILED
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.2-3.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: download.dock er.com; Name or service not known"
Trying other mirror.
docker-ce-cli-19.03.2-3.el7.x8 FAILED
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.2-3.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: download. docker.com; Name or service not known"
Trying other mirror.
Error downloading packages:
1:docker-ce-cli-19.03.2-3.el7.x86_64: [Errno 256] No more mirrors to try.
3:docker-ce-19.03.2-3.el7.x86_64: [Errno 256] No more mirrors to try.
containerd.io-1.2.6-3.3.el7.x86_64: [Errno 256] No more mirrors to try.
[root@cts-dockersrv01 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
--2019-09-17 12:04:15-- https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 27119348 (26M) [binary/octet-stream]
Saving to: ‘containerd.io-1.2.6-3.3.el7.x86_64.rpm’
100%[======================================================================================================================>] 27,119,348 38.7MB/s in 0.7s
2019-09-17 12:04:21 (38.7 MB/s) - ‘containerd.io-1.2.6-3.3.el7.x86_64.rpm’ saved [27119348/27119348]
[root@cts-dockersrv01 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.2-3.el7.x86_64.rpm
--2019-09-17 12:04:34-- https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.2-3.el7.x86_64.rpm
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 25533156 (24M) [binary/octet-stream]
Saving to: ‘docker-ce-19.03.2-3.el7.x86_64.rpm’
100%[======================================================================================================================>] 25,533,156 33.2MB/s in 0.7s
2019-09-17 12:04:40 (33.2 MB/s) - ‘docker-ce-19.03.2-3.el7.x86_64.rpm’ saved [25533156/25533156]
[root@techs-dockersrv01 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.2-3.el7.x86_64.rpm
--2019-09-17 12:04:45-- https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.2-3.el7.x86_64.rpm
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 41397692 (39M) [binary/octet-stream]
Saving to: ‘docker-ce-cli-19.03.2-3.el7.x86_64.rpm’
100%[======================================================================================================================>] 41,397,692 6.42MB/s in 6.1s
2019-09-17 12:04:57 (6.42 MB/s) - ‘docker-ce-cli-19.03.2-3.el7.x86_64.rpm’ saved [41397692/41397692]
[root@techs-dockersrv01 ~]# ls
containerd.io-1.2.6-3.3.el7.x86_64.rpm docker-ce-19.03.2-3.el7.x86_64.rpm docker-ce-cli-19.03.2-3.el7.x86_64.rpm docker-ce.repo index.html
[root@cts-dockersrv01 ~]# yum install docker-ce
Once Docker services are up and running you can check the status with following commands –
docker -V
Now try to create a container with Dockerfile, if see this error, its because of dns settings or a proxy settings, in my case it was due to proxy settings –
techs-dockersrv01 docker02]# docker pull hello-world
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 10.10.10.1:53: no such host
you need to add your proxy details into the /lib/systemd/system/docker.service file –
- create a dockerproxy file in any location - vi /etc/default/dockerproxy
- open docker.service and add this location under [Service] section
- Under Service section you add "EnvironmentFile=/etc/default/dockerproxy"
- sudo systemctl daemon-reload
- sudo systemctl restart docker
Now test by searching any image -
- sudo docker search nodejs
Remove or Uninstall docker
yum remove docker docker-engine docker.io containerd runc
Build an Image from scratch and deploy with docker-compose
Compose involves below steps:
- Create a container as per your application's requirement
- run a base image
- install all required OS modules
- mount the volumes as per requirement
- decide on ports to be exposed and publish the ports
- declare the environment variables
- finally run the image as a container and test everything is working as expected
- once basic image testing is done, its now time to define your tested application environment into a
Dockerfile
, benefit of doing this is that we can re-create it anywhere we need, like server change, network change or DC change. - Define the required services in
docker-compose.yml
to run together in an isolated environment. - Run
docker compose up
or docker-compose up
using the docker-compose binary can also be used, for more reference of these commands refer to docker's documentation.