[BUG] Docker compose up with --build not working offline
Description
Hi 👋
I'm trying (this "cmd") docker compose up --watch --build as I'm developing. All the necessary images are downloaded (pulled) in my machine. Still, it fails to build when theres no internet connection. It seems that docker tries to pull some metadata from the hub. Why is this? How to stop this so the build can succeed?
I'm using all images with specific tag so why is docker trying to fetch metadata?
Is there any way to successfully run above mentioned cmd when offline?
Steps To Reproduce
Run a simple compose file like the following with docker compose up --watch --build
services:
db:
image: mariadb:10.5.25
restart: always
adminer:
image: adminer
restart: always
when it successfully builds then stop the containers, Turn off the network & try to run again.
I'm getting following error:
[+] Building 0.4s (2/2) FINISHED docker:desktop-linux
=> [api internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 363B 0.0s
=> ERROR [api internal] load metadata for docker.io/library/node:20-alpine3.20 0.1s
------
> [api internal] load metadata for docker.io/library/node:20-alpine3.20:
------
failed to solve: node:20-alpine3.20: failed to resolve source metadata for docker.io/library/node:20-alpine3.20: failed to do request: Head "https://registry-1.docker.io/v2/library/node/manifests/20-alpine3.20": dialing registry-1.docker.io:443 container via direct connection because has no HTTPS proxy: connecting to registry-1.docker.io:443: dial tcp: lookup registry-1.docker.io on 127.0.0.53:53: server misbehaving
*/api is a node project
This is the Dockerfile in /api
FROM node:20-alpine3.20 AS build
RUN npm install -g pnpm
WORKDIR /usr/src/app
COPY package.json pnpm-lock.yaml ./
RUN pnpm i --frozen-lockfile
FROM node:20-alpine3.20
WORKDIR /usr/src/app
RUN npm install -g pnpm
COPY --from=build /usr/src/app .
COPY . .
RUN pnpm db:gen:client #gen prisma client
EXPOSE 3000
CMD ["pnpm", "start:dev"]
Compose Version
Docker Compose version v2.29.2-desktop.2
Docker Environment
Client: Docker Engine - Community Version: 27.3.1 Context: desktop-linux Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.16.2-desktop.1 Path: /usr/lib/docker/cli-plugins/docker-buildx compose: Docker Compose (Docker Inc.) Version: v2.29.2-desktop.2 Path: /usr/lib/docker/cli-plugins/docker-compose debug: Get a shell into any image or container (Docker Inc.) Version: 0.0.34 Path: /usr/lib/docker/cli-plugins/docker-debug desktop: Docker Desktop commands (Alpha) (Docker Inc.) Version: v0.0.15 Path: /usr/lib/docker/cli-plugins/docker-desktop dev: Docker Dev Environments (Docker Inc.) Version: v0.1.2 Path: /usr/lib/docker/cli-plugins/docker-dev extension: Manages Docker extensions (Docker Inc.) Version: v0.2.25 Path: /usr/lib/docker/cli-plugins/docker-extension feedback: Provide feedback, right in your terminal! (Docker Inc.) Version: v1.0.5 Path: /usr/lib/docker/cli-plugins/docker-feedback init: Creates Docker-related starter files for your project (Docker Inc.) Version: v1.3.0 Path: /usr/lib/docker/cli-plugins/docker-init sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.) Version: 0.6.0 Path: /usr/lib/docker/cli-plugins/docker-sbom scout: Docker Scout (Docker Inc.) Version: v1.13.0 Path: /usr/lib/docker/cli-plugins/docker-scout
Server: Containers: 14 Running: 0 Paused: 0 Stopped: 14 Images: 70 Server Version: 27.2.0 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Using metacopy: false Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 runc Default Runtime: runc Init Binary: docker-init containerd version: 8fc6bcff51318944179630522a095cc9dbf9f353 runc version: v1.1.13-0-g58aa920 init version: de40ad0 Security Options: seccomp Profile: unconfined cgroupns Kernel Version: 6.10.4-linuxkit Operating System: Docker Desktop OSType: linux Architecture: x86_64 CPUs: 20 Total Memory: 7.51GiB Name: docker-desktop ID: 528bcce9-be10-474a-8f66-a66bb11e4abe Docker Root Dir: /var/lib/docker Debug Mode: false HTTP Proxy: http.docker.internal:3128 HTTPS Proxy: http.docker.internal:3128 No Proxy: hubproxy.docker.internal Labels: com.docker.desktop.address=unix:///home/[USER]/.docker/desktop/docker-cli.sock Experimental: false Insecure Registries: hubproxy.docker.internal:5555 127.0.0.0/8 Live Restore Enabled: false
WARNING: daemon is not using the default seccomp profile // <---- WHAT IS THIS?
Anything else?
No response
This doesn't seem to be a compose issue: You should be able to get the same behavior with a plain docker buildx build ... command. If confirmed, please report on https://github.com/docker/buildx
ANYWAY afaict the builder needs image metadata in cache so it can provide support for advanced features, like multi-platform support. This only happens once first time it is used as initial stage for building your image, then is kept in builder's cache
I think you're correct @ndeloof, but why it doesn't uses from cache with --build flag? is this a bug?
This isn't a bug: builder design require to store more details about the images than the docker engine needs. Typically builder do support multi-platform builds while the engine will only download the one matching the actual platform.
okay, how can I re-build an image when offline then?