• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to configure docker to use proxy

By admin

A proxy is required when the server running Docker does not have direct access to the Internet. Configure the Docker daemon to use a proxy server to access images stored on the official Docker Hub Registry or 3rd-party registries. There are 2 ways to configure the proxy for docker :

  • Configuring proxy variables in the /etc/sysconfig/docker file
  • Configuring environment variables

Method 1 : Configuring proxy variables in the /etc/sysconfig/docker file

1. Add following configuration in /etc/sysconfig/docker file:

# cat /etc/sysconfig/docker
export HTTP_PROXY="http://USERNAME:PASSWORD@[your.proxy.server]:[port]"
export HTTPS_PROXY="https://USERNAME:PASSWORD@[your.proxy.server]:[port]"

For example :

# cat /etc/sysconfig/docker
HTTP_PROXY="http://user01:password@10.10.10.10:8080"
HTTPS_PROXY="https://user01:password@10.10.10.10:8080"

2. Restart the Docker daemon after setting up the proxy.

# service docker restart

Method 2 : Configuring environment variables

1. Create a drop-in

# mkdir /etc/systemd/system/docker.service.d

2. Create a file with name /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

[Service]
Environment="HTTP_PROXY=http://user01:password@10.10.10.10:8080/"
Environment="HTTPS_PROXY=https://user01:password@10.10.10.10:8080/"
Environment="NO_PROXY= hostname.example.com,172.10.10.10"

3. reload the systemd daemon

# systemctl daemon-reload

4. restart docker

# systemctl restart docker

5. Verify that the configuration has been loaded:

# systemctl show docker --property Environment
Environment=GOTRACEBACK=crash HTTP_PROXY=http://10.10.10.10:8080/ HTTPS_PROXY=http://10.10.10.10:8080/ NO_PROXY= hostname.example.com,172.10.10.10

Filed Under: DevOps, Docker

Some more articles you might also be interested in …

  1. Examples of creating command alias in different shells
  2. How to check the status and space used by images and containers
  3. How to add new host entry in /etc/hosts when a docker container is run
  4. How to resolve Docker Search Command Error – “getsockopt: no route to host” in CentOS / RHEL / Fedora
  5. How to Access Docker Container’s Network Namespace from Host
  6. How to Configure Btrfs as the Storage Engine in Docker
  7. Understanding Variables in Bash Shell Under Linux
  8. How to install docker on CentOS / RHEL / Fedora
  9. Understanding Positional Parameters (Passing Parameters/Arguments to Shell script)
  10. 6 Bash Shell Command Line Chaining Operators in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • How to Configure Automatic Package Updates on the Server in CentOS/RHEL 8
  • FATAL: Error inserting rds_rdma
  • Failed to start LSB: Bring up/down networking – On restarting network service CentOS/RHEL (DHCP client)
  • How To Add Timestamps To dmesg Kernel Boot Log in CentOS/RHEL
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary