compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] Watch mode: Deleting files doesn't restart services which have already exited

Open dkaste opened this issue 5 months ago • 5 comments

Description

If my container exits early (e.g. due to a compile error), file delete events don't properly trigger a sync+restart. Instead I get this error message:

WARN[0232] Error handling changed files: 1 error occurred:
        * deleting paths in 2996dfdb5771fe1f20cc98f25dea0fc876fe5be79b9932f2c26ee24036323b3f: Error response from daemon: container 2996dfdb5771fe1f20cc98f25dea0fc876fe5be79b9932f2c26ee24036323b3f is not running

Interestingly, file change events work just fine, as do delete events while the container is still running.

Steps To Reproduce

services:
  test1:
    image: debian
    command: sh -c 'while true; do sleep 2; done'
  test2:
    image: debian
    command: echo "hello"
    develop:
      watch:
        - path: .
          target: /
          action: sync+restart
touch dummy.txt
docker compose up --watch

In another shell:

rm dummy.txt

Back in the original shell you should see an error message similar to the one above, instead of the container being restarted and printing "hello" as expected.

Compose Version

v2.38.2

Docker Environment

Client: Docker Engine - Community
 Version:    28.3.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.25.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.38.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 4
  Running: 3
  Paused: 0
  Stopped: 1
 Images: 5
 Server Version: 28.3.2
 Storage Driver: overlay2
  Backing Filesystem: btrfs
  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
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.15.5-200.fc42.x86_64
 Operating System: Fedora Linux 42 (Workstation Edition)
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 30.95GiB
 Name: jupiter
 ID: 821b19f5-dabc-4982-814b-7ec792078a06
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

dkaste avatar Jul 17 '25 01:07 dkaste

Hey @dkaste This is because test2 service was already stopped, due to the echo "Hello", when you try to delete the file inside the container. You should have the same behaviour if you create a new file or try to change the content of the dummy.txt file

~/tmp/issue-13057 > touch dummy.txt                                                                                                                                                                                               11s 10:05:26
~/tmp/issue-13057 > docker compose up --watch                                                                                                                                                                                         10:10:25
[+] Running 2/2
 ✔ test2 Pulled                                                                                                                                                                                                                           2.1s
 ✔ test1 Pulled                                                                                                                                                                                                                           2.1s
[+] Running 3/3
 ✔ Network issue-13057_default    Created                                                                                                                                                                                                 0.1s
 ✔ Container issue-13057-test2-1  Created                                                                                                                                                                                                 0.3s
 ✔ Container issue-13057-test1-1  Created                                                                                                                                                                                                 0.3s
        ⦿ Watch enabled
Attaching to test1-1, test2-1
test2-1  | hello
test2-1 exited with code 0

glours avatar Jul 29 '25 08:07 glours

Doesn't that kind of defeat the purpose of watch mode?

In a typical development workflow you may cause errors in the container that cause it to terminate. Then you would go fix the error and have watch mode automatically detect the change and restart, no?

Also, as I mentioned, file change events do in fact restart the container as I expect. File delete events do not. Replace the rm dummy.txt in my example reproduction with another touch dummy.txt, and the container will restart properly. Creating new files also seems to restart the exited container.

This is particularly annoying with the Helix text editor, which always causes a delete event when saving files.

dkaste avatar Jul 31 '25 22:07 dkaste

After a little investigation, I realized that I wasn't properly using exec in my entrypoint scripts. Correcting that seems to have fixed my problems.

dkaste avatar Aug 15 '25 04:08 dkaste

I'm not sure why it seemed to be working the other day, but this is definitely still an issue.

dkaste avatar Aug 19 '25 18:08 dkaste

@dkaste is the issue up for grabs....I want to work on it.

puneeth072003 avatar Oct 17 '25 10:10 puneeth072003