0

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.

Taxellool
  • 3,743
  • 3
  • 20
  • 36

2 Answers2

1

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
Taxellool
  • 3,743
  • 3
  • 20
  • 36
0

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.

Mihai
  • 6,641
  • 1
  • 13
  • 31
  • I tried restrting as explained [here](https://stackoverflow.com/a/20431030/3287262). even reinstalled docker. but didnt fix it. also tried --no-cache and no luck :( – Taxellool Sep 20 '20 at 18:42