1

I'm using Docker on Windows via WSL (Windows Subsystem for Linux). When I was using Docker Desktop directly, setting up the proxy worked fine for both docker run and docker build commands. However, when using Docker through WSL with an Ubuntu environment, the proxy settings don't seem to be applied during the docker build process.

I'm using Docker on Windows through WSL (Windows Subsystem for Linux). I've configured proxy settings in several places:

  • Set environment variables for proxy in /etc/environment
http_proxy=http://username:[email protected]:3128
https_proxy=http://username:[email protected]:3128
  • Configured proxy settings in /etc/docker/daemon.json
{
    "proxies": {
        "http-proxy": "http://username:[email protected]:3128",
        "https-proxy": "http://username:[email protected]:3128",
        "no-proxy": "localhost,127.0.0.1,docker-registry.somecorporation.com"
    },
    "insecure-registries": ["mcr.microsoft.com"]
}
  • Added proxy settings in /etc/systemd/system/docker.service.d/proxy.conf
[Service]
Environment="http_proxy=http://username:[email protected]:3128"
Environment="https_proxy=http://username:[email protected]:3128"
Environment="no_proxy=localhost,127.0.0.1,docker-registry.somecorporation.com"

The proxy works correctly with apt and docker pull commands within WSL. However, when I run docker build, the apt commands inside the Dockerfile do not use the proxy settings.

This my dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN apt-get update && \
    apt-get install -y libldap2-dev && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

COPY ["EQP_Workspace/EQP_Workspace.csproj", "EQP_Workspace/"]
RUN dotnet restore "EQP_Workspace/EQP_Workspace.csproj"
COPY . .
WORKDIR "/src/EQP_Workspace"
RUN dotnet build "EQP_Workspace.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "EQP_Workspace.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EQP_Workspace.dll"]

And this error message

[eqp_workspace base 3/3] RUN apt-get update &&     apt-get install -y libldap2-dev &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*:
30.69 Ign:1 http://deb.debian.org/debian bookworm InRelease
30.70 Ign:2 http://deb.debian.org/debian bookworm-updates InRelease
30.70 Ign:3 http://deb.debian.org/debian-security bookworm-security InRelease
31.70 Ign:1 http://deb.debian.org/debian bookworm InRelease
31.70 Ign:2 http://deb.debian.org/debian bookworm-updates InRelease
31.71 Ign:3 http://deb.debian.org/debian-security bookworm-security InRelease
33.70 Ign:1 http://deb.debian.org/debian bookworm InRelease
33.71 Ign:2 http://deb.debian.org/debian bookworm-updates InRelease
33.71 Ign:3 http://deb.debian.org/debian-security bookworm-security InRelease
37.70 Err:1 http://deb.debian.org/debian bookworm InRelease
37.70   Could not connect to deb.debian.org:80 (199.232.46.132), connection timed out
37.71 Err:2 http://deb.debian.org/debian bookworm-updates InRelease
37.71   Unable to connect to deb.debian.org:80:
37.71 Err:3 http://deb.debian.org/debian-security bookworm-security InRelease
37.71   Unable to connect to deb.debian.org:80:
37.71 Reading package lists...
37.72 W: Failed to fetch http://deb.debian.org/debian/dists/bookworm/InRelease  Could not connect to deb.debian.org:80 (199.232.46.132), connection timed out
37.72 W: Failed to fetch http://deb.debian.org/debian/dists/bookworm-updates/InRelease  Unable to connect to deb.debian.org:80:
37.72 W: Failed to fetch http://deb.debian.org/debian-security/dists/bookworm-security/InRelease  Unable to connect to deb.debian.org:80:
37.72 W: Some index files failed to download. They have been ignored, or old ones used instead.
37.72 Reading package lists...
37.73 Building dependency tree...
37.73 Reading state information...
37.73 E: Unable to locate package libldap2-dev
------
time="2024-07-24T14:59:07+08:00" level=warning msg="current commit information was not captured by the build" error="git was not found in the system: exec: \"git.exe\": executable file not found in %PATH%"
failed to solve: process "/bin/sh -c apt-get update &&     apt-get install -y libldap2-dev &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100

I need to ensure that the proxy settings applied in Docker Desktop are also used during the docker build process within WSL.

How can I ensure that Docker build commands properly use the configured proxy settings?

0

1 Answer 1

1

docker pull will use the proxy settings from the daemon, but docker build requires setting the proxy for the Docker CLI.

I configured the proxy in the ~/.docker/config.json file on Windows, and it works.

{
    "proxies": {
        "default": {
            "httpProxy": "http://username:[email protected]:3128",
            "httpsProxy": "http://username:[email protected]:3128"
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.