Skip to content

Instantly share code, notes, and snippets.

@xterat
Created March 5, 2018 15:17
Show Gist options
  • Save xterat/02170fcc7bb08db382367a3a4d370f5f to your computer and use it in GitHub Desktop.
Save xterat/02170fcc7bb08db382367a3a4d370f5f to your computer and use it in GitHub Desktop.

Use docker behind proxy

When I run docker run hello-world, I get error message "docker: Error response from daemon: Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid.". Here is the solution to this problem.

  1. Create a systemd drop-in directory for the docker service:

    $ mkdir -p /etc/systemd/system/docker.service.d
  2. Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

    [Service]
    Environment="HTTP_PROXY=http://proxy.example.com:80/"
  3. If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:

    Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
  4. Flush changes:

    $ sudo systemctl daemon-reload
  5. Verify that the configuration has been loaded:

    $ systemctl show --property=Environment docker
    Environment=HTTP_PROXY=http://proxy.example.com:80/
  6. Restart Docker:

    $ sudo systemctl restart docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment