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.