Docker compose command can't stop a container

Hello,
I have the following containers:

# docker compose ps -a
NAME                   IMAGE          COMMAND                  SERVICE   CREATED             STATUS                         PORTS
containers-nginx-1     nginx:latest   "/docker-entrypoint.…"   nginx     About an hour ago   Up About an hour               0.0.0.0:80->80/tcp, :::80->80/tcp
containers-php-1       php:latest     "docker-php-entrypoi…"   php       About an hour ago   Exited (0) About an hour ago   
containers-php-fpm-1   php:8-fpm      "docker-php-entrypoi…"   php-fpm   12 minutes ago      Exited (0) 7 minutes ago       
containers-web-1       nginx:latest   "/docker-entrypoint.…"   web       12 minutes ago      Created

I want to stop the Nginx:

# docker compose stop nginx
no such service: nginx

And:

# ss -tupln
Netid        State         Recv-Q        Send-Q               Local Address:Port                 Peer Address:Port        
tcp          LISTEN        0             4096                       0.0.0.0:80                        0.0.0.0:*            users:(("docker-proxy",pid=5146,fd=4))        
tcp          LISTEN        0             4096                          [::]:80                           [::]:*            users:(("docker-proxy",pid=5153,fd=4))

Why? What is wrong?

Cheers.

The service name looks right. Check the version of docker compose and update it if there i a newer release.

Or maybe there was an nginx service but it is not in the compsoe file anymore. I haven’t checked what happens in that case, but if it is the case, it is still inconsistent as it should be able to stop the container that it can list.

1 Like

Hello,
Thank you so much for your reply.
I am using Debian 12 and the latest version of Docker Compose. Is my method of stopping a container correct?

Yes, you tried correctly.

Please, show the output of the following commands:

docker info
docker version

And if you could share the compose file that could help us recognize if there is something wrong with it.

1 Like

Hi,
Thanks again.
Please take a look at these:

# docker info
Client: Docker Engine - Community
 Version:    25.0.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 2
  Running: 1
  Paused: 0
  Stopped: 1
 Images: 3
 Server Version: 25.0.4
 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: systemd
 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: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.0-9-amd64
 Operating System: Debian GNU/Linux 12 (bookworm)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.799GiB
 Name: Docker
 ID: 05bdcabe-9fee-48a5-80c5-5d701838afec
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
#
# docker version
Client: Docker Engine - Community
 Version:           25.0.4
 API version:       1.44
 Go version:        go1.21.8
 Git commit:        1a576c5
 Built:             Wed Mar  6 16:32:14 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.4
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       061aa95
  Built:            Wed Mar  6 16:32:14 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

That seems right. Can you also share the compose file or create a new compose file for us that can reproduce the issue? The latest compose can have bugs as well. Maybe you can try to downgrade it.

I assume you installed Docker from the official repo:

Are you in the folder with the compose file when you execute the docker compose command?

1 Like

Hello,
This problem solved by restarted the docker daemon.