0

I'm trying to access an HTTP proxy from a container that was created using docker in docker. I'm doing this on a Kubernetes worker that still has docker available. This is what my deployment looks like,

apiVersion: apps/v1
kind: Deployment
metadata:
  name: alpine
  labels:
    app: alpine
spec:
  replicas: 1
  selector:
    matchLabels:
      app: alpine
  template:
    metadata:
      labels:
        app: alpine
    spec:
      containers:
      - name: alpine
        image: alpine:3
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5 ; done"]
        volumeMounts:
        - name: docker-socket
          mountPath: /var/run/docker.sock
      volumes:
      - name: docker-socket
        hostPath:
          path: /var/run/docker.sock

It's a simple Deployment using the official alpine:3 image. The worker has docker installed so I'm able to mount in the docker.sock file.

Now I exec into that Alpine 3 pod/container so that I can install docker. I cannot install the package or run apk update until I set the proxy environment variables: HTTP_PROXY, HTTPS_PROXY, and NO_PROXY. Once those are set I'm able to update apk and install the docker package.

Now that docker is installed I run another container using,

docker run -it --rm alpine:3 sh

Now I have a shell in this new Alpine 3 container. Again I cannot run apk update because I am behind an HTTP proxy. So I set the three environment variables again. But this time I still cannot run apk update or apk add curl or access the internet as I was in the host container.

Does anyone know why I cannot use the HTTP proxy in a container started from within another? Or what I may be missing to make this work? I spent the better of a day searching the internet and discussing with coworkers but cannot find a solution. Many thanks.

wsams
  • 2,499
  • 7
  • 40
  • 51
  • Did you check the network for DinD ? using ifconfig and the MTU config at docker network side ? – Harsh Manvar Nov 10 '21 at 04:07
  • Hi @HarshManvar, I was just tinkering with `ifconfig`. I did find out if I add `--network host` I do have network access in the nested container, however my real use case is using a Kubernetes pod as a GitHub Actions self-hosted runner. My workflows run in a container so when one of the actions tries to build a docker image it has no access to the network. Maybe there's a way to pass `--network host` in the runner. This issue clued me in: https://github.com/containers/podman/issues/5188 – wsams Nov 10 '21 at 05:29

0 Answers0