Running Docker apps in VM which need proxy to connect to Internet


For systems, which can't connect to Internet without a proxy

Note: If your computer or VM in which you are about to install docker is not connected to Internet directly, then you can use a http(s) proxy. This is the case with most development VMs in the corporates which are generally not exposed to the Internet. Check with your IT team and get a proxy. Once you get a proxy, set it to your VM using the following guide.

Add the following lines to your ~/.bashrc file, so that they will be set when you startup.

vi ~/.bashrc
export https_proxy=https://x.x.x.x:3128
export http_proxy=http://x.x.x.x:3128

Sometimes, (as it happened to me), the yum.conf also needs a proxy. Otherwise, you might get a timeout error. Though the curl works, you will face the issue with yum. So add the following line to your /etc/yum.conf file
Note: Mostly, the port will be 3128. If not, check with your IT team.


Installing Docker CE on CentOS 7.5

It is recommended to do a yum update before you proceed:

sudo yum update

Here, I am going to use CentOS 7.5. You need to download Docker into it, probably using yum package manager. Most of the steps taken here are from the official guide

You need to install the following packages, before you install docker:

sudo yum install -y yum-utils \
     device-mapper-persistent-data \
     lvm2

Add the repo, so that you can get future updates easily.

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

Now, install the docker-ce

sudo yum install docker-ce

The above will install the latest docker-ce version.

Now, you are ready to go

Start the docker service
sudo systemctl start docker

Check its status:
sudo systemctl status docker

It must be active and running.

Now, you can run the hello-world.

But, again, for the systems which need proxy to be setup to connect to Internet, the following guide will help.

vi /etc/systemd/system/docker.service.d/http-proxy.conf

In the above file, write the following lines:
[Service]  Environment="HTTP_PROXY=http://x.x.x.x:3128"
and again, for https proxy,

vi /etc/systemd/system/docker.service.d/https-proxy.conf
[Service]  Environment="HTTPS_PROXY=http://x.x.x.x:3128"

As you can see, though https proxy comes with https:// prefix, we left that to http:// only. Because, for some reason, setting to https:// did not work.

Check if the proxies are set:
systemctl show --property=Environment docker
When you run the above, you should see your proxy configuration.

If you don't see above, just do the following:
sudo systemctl daemon-reload  sudo systemctl restart docker


Now, run the hello-world app
docker run hello-world  
This fetches the hello-world image from the docker hub (if it is already not present) and then executes it.

No comments: