4

I have checked a lot of similar questions on both stack and superuser but could not find my exact case so I decided to ask this.

My problem is that my container does not have internet access ONLY DURING BUILD PROCESS. Means that if i comment out any internet requiring command from my Dockerfile and set the execute command to tail -f /dev/null and then go to container shell, then I do have internet access.

here is my failing set up:

my docker-compose.yml:

version: '3.7'
services:
  admin-panel:
    network_mode: host
    container_name: react-admin
    build:
      context: Admin-Panel
    volumes:
      - ./Admin-Panel:/app
      - /app/node_modules
    ports:
      - '5000:5000'
    stdin_open: true
    tty: true

and the Dockerfile:

FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json yarn.lock ./
RUN yarn --pure-lockfile --silent
COPY . ./
RUN yarn build
CMD ["serve" "-s" "build"]

This will fail with this output:

docker-compose up --build
Building admin-panel
Step 1/9 : FROM node:13.12.0-alpine
 ---> 483343d6c5f5
Step 2/9 : WORKDIR /app
 ---> Using cache
 ---> 5cd6ae583081
Step 3/9 : ENV PATH /app/node_modules/.bin:$PATH
 ---> Using cache
 ---> 77db61e579e4
Step 4/9 : COPY package.json yarn.lock ./
 ---> Using cache
 ---> 52e5361fb0fa
Step 5/9 : RUN yarn --pure-lockfile --silent
 ---> Running in 803c8d85c8e5
error An unexpected error occurred: "https://registry.yarnpkg.com/clsx/-/clsx-1.1.0.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com".

which indicates no internet access.

But when i comment out yarn commands and do them manually after the build is done and im in container's shell, everything works.

working setup:

same docker-compose with this Dockerfile:

FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json yarn.lock ./
# RUN yarn --pure-lockfile --silent
COPY . ./
# RUN yarn build
# CMD ["serve" "-s" "build"]
CMD ["tail", "-f", "/dev/null"]

and installing dependencies and running the app from container shell manually.

Any idea why this no internet thing happens only in build process?

P.S: If I remove network_mode: host from my docker-compose.yml I would NOT have internet even after build.

3 Answers 3

7

my problem was solved by adding network: host to build section.

still no idea why my docker bridge network is not working.

version: '3.7'
services:
  admin-panel:
    network_mode: host
    container_name: react-admin
    build:
      context: Admin-Panel
      # the line below fixed it
      network: host
    volumes:
      - ./Admin-Panel:/app
      - /app/node_modules
    ports:
      - '5000:5000'
    stdin_open: true
    tty: true
0
network_mode: host

Does not seem to be an optimal solution as it disables network isolation and port-mapping.

I had the exact same issue and did not find a fix for months. I have the following scenario inside a company network:

  • Containers must not use the default IP range of docker0
  • Containers must use a defined network and IP adresses

So i create a network in my docker-compose file like so:

networks:
  custom_network:
    ipam:
      driver: default
      config:
        - subnet: "192.168.100.80/28" 

And in addition i removed the default bridge for the docker daemon via /etc/docker/daemon.json:

{
  "bridge" : "none"
}

The result is: docker-compose is able to pull, but dockerfile RUN commands fail as obviously the host network is not used to execute dockerfile RUN commands, but docker tries to go via the (non existing) docker0 default bridge.

But the containers do have internet access, as they use the custom network - very nasty. So even the custom network definition does not help in this case, as the custom bridge is not used, or created after processing the dockerfile.

So in case you want to run docker/docker-compose build including RUN commands in your dockerfile, you cannot simply remove docker0 default bridge.

The final solution was to make docker happy and allow docker0 bridge, but with a customized IP range. For example:

{
  "default-address-pools":
  [
    {"base":"192.168.100.80/24","size":28}
  ]
}

This will allow docker to use the docker0 network, but prevent docker from using 172.17.0.0/16 network - and allow your RUN commands to work again.

-1

If only network_mode host works for you then it means that docker's bridge network is "stuck". Restarting the docker daemon should fix the issue.

During build time docker creates ephemeral containers/images. Normally they are removed upon successful build but they also can get "stuck". Try to build your image using the "--no-cache" flag. From the output you posted all the previous layers in your build are cached layers.

1
  • I tried restrting as explained here. even reinstalled docker. but didnt fix it. also tried --no-cache and no luck :(
    – Taxellool
    Commented Sep 20, 2020 at 18:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.