Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull_policy: build pulls anyway before building #9717

Closed
codl opened this issue Aug 4, 2022 · 0 comments · Fixed by #9720
Closed

pull_policy: build pulls anyway before building #9717

codl opened this issue Aug 4, 2022 · 0 comments · Fixed by #9720

Comments

@codl
Copy link

codl commented Aug 4, 2022

Description

If a service has pull_policy: build, I would expect that its image would never be pulled. However docker-compose up and create will try to pull it the image doesn't exist, and then build it and tag the built image on top of the pulled image.

Steps to reproduce the issue:

  1. Have a docker-compose.yml with a service with an image name, build context, and pull_policy: build
  2. Ensure that the named image doesn't exist
  3. Run docker-compose create or up
$ docker pull hello-world
$ docker images
...
hello-world            latest          feb5d9fea6a5   10 months ago    13.3kB
...
$ docker rmi hello-world
$ docker images | grep feb5d9fea6a5
$ # nothing, this is normal
$ cat > Dockerfile << EOF
FROM alpine
RUN echo
CMD ["echo", "I am not hello-world"]
EOF
$ cat > docker-compose.yml << EOF
services:
  hello-world:
    image: hello-world
    build: .
    pull_policy: build
EOF
$ docker-compose up
[+] Running 2/2
 ⠿ hello-world Pulled                                                                                                                                                                      2.7s
   ⠿ 2db29710123e Pull complete                                                                                                                                                            0.6s
[+] Building 0.1s (5/5) FINISHED                                                                                                                                                                
 => [internal] load build definition from Dockerfile                                                                                                                                       0.0s
 => => transferring dockerfile: 87B                                                                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                                            0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                           0.0s
 => CACHED [1/2] FROM docker.io/library/alpine                                                                                                                                             0.0s
 => [2/2] RUN echo                                                                                                                                                                         0.5s
 => exporting to image                                                                                                                                                                     0.4s
 => => exporting layers                                                                                                                                                                    0.4s
 => => writing image sha256:9048e15af052267db498ed68a56cac4a6a0ee32810155b3cfb9829cf5819140a                                                                                               0.0s
 => => naming to docker.io/library/hello-world                                                                                                                                             0.0s
[+] Running 2/2
 ⠿ Network testcase_default          Created                                                                                                                                               0.0s
 ⠿ Container testcase-hello-world-1  Created                                                                                                                                               0.1s
Attaching to testcase-hello-world-1
testcase-hello-world-1  | I am not hello-world
testcase-hello-world-1 exited with code 0
$ docker images | grep hello-world
hello-world            latest          9048e15af052   About a minute ago   5.52MB                                                                                                                                              
hello-world            <none>          feb5d9fea6a5   10 months ago    13.3kB
$ # our built image is here and tagged latest, which is normal
$ # but the image from docker hub, that we deleted earlier, has been pulled again

Describe the results you received:
The named image is downloaded from the repo before being built locally.

Describe the results you expected:
The repo is never contacted and the image is built locally.

Output of docker compose version:

Docker Compose version 2.9.0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  compose: Docker Compose (Docker Inc., 2.9.0)

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 66
 Server Version: 20.10.17
 Storage Driver: btrfs
  Build Version: Btrfs v5.18.1
  Library Version: 102
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.55-2-lts
 Operating System: Arch Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.456GiB
 Name: peanut.codl.fr
 ID: HTBR:M3DN:3IFA:VREG:7FMW:REU4:X23W:UUSQ:33P4:WQ74:CZTP:IHAT
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant