The problem is that docker compose cannot build image, failing on RUN npm ci. But after hours of debugging, I isolated the problem and pinned it in this minimal setup:
My docker-compose.yml
version: '3.8'
services:
myapp:
build:
dockerfile: Dockerfile
context: .
target: development
command: sleep Infinity
My Dockerfile
FROM node:18-alpine AS development
RUN ping google.com
When I run docker compose -f docker-compose.yml up -d --build
I'm getting error:
What I tried so far
- In Dockerfile replace
ping google.comtoping <real-ip>. ✅ And it works, so I assume it's DNS problem. - Add
dnsinto docker-compose.yml:dns: 8.8.8.8. ❌ No luck - Run under super user
sudo docker compose …. ❌ No luck - I tried to build image from Dockerfile without compose, using just
docker buildcommand. ✅ And it works, so the problem withdocker compose. - Commented
RUN ping …command, so it does not fail and runssleep Infinityform the compose config. Then I connected into the container viadocker exec -it <container> shand was able to ping google and runnpm ci. So when container is running it has access to DNS. The problem happens only in docker compose on the build stage from Dockerfile.
Environment
It's a VPS on hetzner. I ssh under a user with sudo and docker group.