Docker Error when proxy is set : proxyconnect tcp: dial tcp: lookup http: no such host

2 min read 06-10-2024
Docker Error when proxy is set : proxyconnect tcp: dial tcp: lookup http: no such host


Docker Error: "proxyconnect tcp: dial tcp: lookup http: no such host" - Troubleshooting & Solutions

Docker is a powerful tool for building and deploying applications, but you might encounter errors when using it, especially if you're working behind a proxy server. One common error is "proxyconnect tcp: dial tcp: lookup http: no such host". This error usually indicates a problem with Docker's connection to the internet through your proxy.

Scenario:

Imagine you're trying to build a Docker image that needs to download dependencies from the internet. Your network is configured to access the internet through a proxy server. You've correctly set up your proxy environment variables in Docker, but you still encounter the error "proxyconnect tcp: dial tcp: lookup http: no such host".

Original Code (Dockerfile):

FROM node:16

# Set proxy environment variables
ENV http_proxy http://your-proxy-server:port
ENV https_proxy http://your-proxy-server:port

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn install

COPY . .

CMD ["yarn", "start"]

What's happening?

This error usually happens because:

  1. Incorrect Proxy Configuration: The proxy server address or port is incorrect in your Docker environment variables. Double-check the proxy details.
  2. Proxy Authentication Issues: If your proxy server requires authentication, Docker might not have the correct credentials to connect.
  3. Proxy Server Down: The proxy server itself might be down or unreachable.
  4. Firewall Blocking: Your firewall might be blocking Docker's access to the proxy server.

Troubleshooting Steps:

  1. Verify Proxy Details: Ensure the http_proxy and https_proxy environment variables are set correctly with the correct server address and port.
  2. Authentication: If your proxy server requires authentication, use the following format:
    http_proxy=http://username:password@your-proxy-server:port
    https_proxy=https://username:password@your-proxy-server:port
    
  3. Check Proxy Server Status: Confirm that your proxy server is running and accessible.
  4. Firewall Configuration: Temporarily disable your firewall and see if the error persists. If it does, check if there are specific rules blocking Docker's access.
  5. Docker Daemon Configuration: You can configure the proxy settings directly in your Docker daemon configuration file (usually located at /etc/docker/daemon.json). Add the following parameters:
    {
        "proxies": {
            "http": "http://your-proxy-server:port",
            "https": "https://your-proxy-server:port"
        }
    }
    
    Then restart the Docker daemon: sudo systemctl restart docker

Additional Tips:

  • Use Docker Desktop: If you're on Windows or macOS, Docker Desktop provides a user-friendly interface for managing proxy settings.
  • Try a Different Proxy Server: If possible, test your Docker setup with a different proxy server to isolate the issue.
  • Check Network Connectivity: Run a simple ping or curl command to verify your internet connection and access to the proxy server.

Remember: Always ensure your proxy settings are consistent between your Docker environment and your local system for smooth operations.

References:

By following these troubleshooting steps and ensuring the correct proxy configuration, you can resolve the "proxyconnect tcp: dial tcp: lookup http: no such host" error and continue building your Docker images seamlessly.