compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] docker compose up after down of specific services fails with network not found

Open ToshY opened this issue 2 years ago • 2 comments

Description

At host system startup or restart of docker, performing a docker compose ps in the myproject directory shows the following:

NAME                IMAGE               COMMAND             SERVICE             CREATED             STATUS              PORTS

While there are no services active now, performing a docker compose down phpfpm nginx shows containers and network being removed.

[+] Running 3/3
 ✔ Container myproject-phpfpm-1  Removed                                                                                                                                                                                       0.0s
 ✔ Container myproject-nginx-1   Removed                                                                                                                                                                                       0.0s
 ✔ Network myproject_project     Removed     

The behavior that there are seemingly containers active seems a bit strange to me. Before the system shutdown these containers were indeed up, but as they have no restart key in the config, they have not been restarted (docker container ls correctly only shows the reverse proxy container is automatically restarted after restart which is ok).

Anyway, I went and performed docker compose up -d. This however now causes a network error:

[+] Running 3/5
 ✔ Network myproject_project     Created                                                                                                                                                                                       0.1s
 ✔ Container myproject-nginx-1   Started                                                                                                                                                                                       1.0s
 ✔ Container myproject-phpfpm-1  Started                                                                                                                                                                                       0.7s
 ⠿ Container myproject-mail-1    Starting                                                                                                                                                                                      1.0s
 ⠿ Container myproject-wait-1    Starting                                                                                                                                                                                      1.0s
Error response from daemon: network 2d38971f26ab4192ccf91b8e43686275aa3fe8e4366619411e089f2796fb5fd2 not found

So instead, I tried docker compose down directly after this:

[+] Running 5/5
 ✔ Container myproject-mail-1    Removed                                                                                                                                                                                       0.0s 
 ✔ Container myproject-wait-1    Removed                                                                                                                                                                                       0.0s 
 ✔ Container myproject-phpfpm-1  Removed                                                                                                                                                                                       0.6s 
 ✔ Container myproject-nginx-1   Removed                                                                                                                                                                                       1.1s 
 ✔ Network myproject_project     Removed                                                                                                                                                                                       0.3s

Again performing a docker compose up -d, and now it creates the network and starts containers without any issues.

[+] Running 5/5
 ✔ Network myproject_project     Created                                                                                                                                                                                       0.1s 
 ✔ Container myproject-mail-1    Started                                                                                                                                                                                       1.4s 
 ✔ Container myproject-nginx-1   Started                                                                                                                                                                                       1.4s 
 ✔ Container myproject-wait-1    Started                                                                                                                                                                                       1.0s 
 ✔ Container myproject-phpfpm-1  Started                                                                                                                                                                                       1.0s 

After reaching this state (where containers are running), I can now perform docker compose down phpfpm nginx without a problem (shows the network is still in use). However if I restart docker again in this state, and run docker compose down phpfpm nginx again then the issue occurs again.

Steps To Reproduce

/var/www/projects/myproject/docker-compose.yml

version: '3.9'

services:
  phpfpm:
    image: php:fpm-alpine
    volumes:
      - .:/app
    networks:
      - project

  nginx:
    image: nginx:alpine
    environment:
      VIRTUAL_HOST: dev.myproject.com
    volumes:
      - .:/app
    networks:
      - project
      - shared

  mail:
    image: marlonb/mailcrab:latest
    networks:
      - project

  wait:
    image: waisbrot/wait
    environment:
      TARGETS: phpfpm:9000
      TIMEOUT: 900
    networks:
      - project

networks:
  project:
    driver: bridge
  shared:
    name: reverseproxy
    external: true
  1. Up the services above, docker compose up -d
owner@LAPTOP: /var/www/projects/myproject $ docker compose up -d
[+] Running 5/5
 ✔ Network myproject_project     Created                                                                                                                                                                                       0.1s 
 ✔ Container myproject-mail-1    Started                                                                                                                                                                                       1.1s 
 ✔ Container myproject-wait-1    Started                                                                                                                                                                                       1.1s 
 ✔ Container myproject-phpfpm-1  Started                                                                                                                                                                                       1.5s 
 ✔ Container myproject-nginx-1   Started                                                                                                                                                                                       1.6s
  1. Restart docker, e.g. sudo systemctl restart docker
owner@LAPTOP: /var/www/projects/myproject $ sudo systemctl restart docker
  1. Run docker compose down phpfpm nginx
owner@LAPTOP: /var/www/projects/myproject $ docker compose down phpfpm nginx
[+] Running 3/3
 ✔ Container myproject-phpfpm-1  Removed                                                                                                                                                                                       0.0s 
 ✔ Container myproject-nginx-1   Removed                                                                                                                                                                                       0.0s 
 ✔ Network myproject_project     Removed                                                                                                                                                                                       0.2s 
  1. Run docker compose up -d
owner@LAPTOP: /var/www/projects/myproject $ docker compose up -d
[+] Running 3/5
 ✔ Network myproject_project     Created                                                                                                                                                                                       0.1s 
 ✔ Container myproject-phpfpm-1  Started                                                                                                                                                                                       0.9s 
 ✔ Container myproject-nginx-1   Started                                                                                                                                                                                       1.1s 
 ⠿ Container myproject-wait-1    Starting                                                                                                                                                                                      1.1s 
 ⠿ Container myproject-mail-1    Starting                                                                                                                                                                                      1.1s 
Error response from daemon: network 9649117b94d648e527da3441a732eed431a520378ae4df9d757cf66f493847ce not found

Compose Version

v2.20.2

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.4
    Path:     /home/<user>/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.20.2
    Path:     /home/<user>/.docker/cli-plugins/docker-compose
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-dev" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-dev: no such file or directory
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-extension" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-extension: no such file or directory
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-sbom" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-sbom: no such file or directory
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-scan" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-scan: no such file or directory
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-scout" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-scout: no such file or directory

Server:
 Containers: 43
  Running: 1
  Paused: 0
  Stopped: 42
 Images: 55
 Server Version: 23.0.1
 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: 1
 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: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.761GiB
 Name: LAPTOP-8JM9CUVJ
 ID: 7DN2:QJQW:O7VZ:3BJB:FPYV:CVXN:HOKZ:DG2W:XRSB:QSCD:YDXH:HDZ2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

Anything else?

No response

ToshY avatar Jul 26 '23 08:07 ToshY

Does this issue need additional information, are the steps unclear, or can it not be reproduced? Would be nice if there is some form of feedback 🙂

ToshY avatar Sep 07 '23 13:09 ToshY

docker compose ps only list running containers, add --all to also list the stopped ones.

network not found error on up is unclear to me, have no idea what could be the root cause (maybe a race condition?)

ndeloof avatar Oct 18 '23 12:10 ndeloof