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

Ensure Docker Compose syncs file changes after a container in the stack is stopped, modified, and restarted #12592

Closed
harperl1 opened this issue Feb 28, 2025 · 1 comment

Comments

@harperl1
Copy link

harperl1 commented Feb 28, 2025

Description

Hi,

Currently if I stop a container via Docker Desktop etc in a specification like below:

docker compose --profile x -f docker-compose.yml --watch --build

auth-console-api:
    build:
      context: ./auth-console-api
      dockerfile: dockerfile.local
      args:
        VERSION: "0.0.1"
    container_name: auth-console-api
    profiles: ["x"]
    depends_on:
      openfga:
        condition: service_healthy
        restart: true
    environment: []
    ports:
      - 5001:80
    develop:
      watch:
        - action: sync
          path: ./auth-console-api/src/AuthConsoleApi
          target: /code/app/src/AuthConsoleApi
          x-initialSync: true
          ignore:
            - appsettings.json
            - bin/
            - obj/
        - action: sync+restart
          path: ./auth-console-api/docker/appsettings-local.json
          target: /code/app/src/AuthConsoleApi/appsettings.json
          x-initialSync: true
    healthcheck:
      test: ["CMD-SHELL", "curl --fail http://localhost:80/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 10

And then while stopped I change some files, and start the container up again via Docker Desktop, the files are not re-synced until I manually do CTRL + S in something like Visual Studio on the host (I am assuming when I do this the file modification date changes and watch picks it up) or stop the whole compose stack and start over again. Ideally, when the container is started any changed files are picked up without having to manually trigger the watch sync via forcing a file modification time change or a full restart of the compose stack.

I think specifically what I mean is for:

x-initialSync: true

Can this be not only an initial sync on compose stack start but an initial sync on a container that has been stopped and started within the runtime of a watching compose stack i.e. when the container is restarted pick up any files where last modified date is after the time the container was stopped.

Use case for this is when working with .NET projects hot reloading and debugging via attach to process can be annoying because after a hot reload we can no longer attach to the Docker container until the container is restarted. So instead sometimes we stop a single .NET container, do some debugging and make some file changes on the host PC and when done bring the container up again.

For context I am using Windows and Docker Compose v2.32.4.

@harperl1 harperl1 changed the title When stopping and starting a container, docker compose watch specification should sync any changed files Docker compose watch should sync any changed files changed while a container in the compose stack has been stopped and started Feb 28, 2025
@harperl1 harperl1 changed the title Docker compose watch should sync any changed files changed while a container in the compose stack has been stopped and started Docker compose watch should sync any changed files changed after a container in the compose stack has been stopped and started Feb 28, 2025
@harperl1 harperl1 changed the title Docker compose watch should sync any changed files changed after a container in the compose stack has been stopped and started Ensure Docker Compose syncs file changes after a container in the stack is stopped, modified, and restarted Feb 28, 2025
@ndeloof
Copy link
Contributor

ndeloof commented Feb 28, 2025

As you start container by Docker Desktop UI (or docker stop / docker start command), compose is not involved. initialSync is only supported by Compose and is not part of the container definition (this is a client feature, docker engine isn't aware)

I'm closing this issue as "not planned": watch is a compose feature, only supported when using compose commands

@ndeloof ndeloof closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants