Skip to content

[BUG] docker compose up --watch does not respect Dockerfile.dockerignore #12191

@danrot

Description

@danrot

Description

I am having a project in which we have a .docker folder in which we keep the Dockerfile for everything related to this project. In there we would like to use the Dockerfile.dockerignore notation to have a separate .dockerignore file for all Dockerfiles. While this file seems to be respected during the initial docker compose up --watch step, it does not seem to respect it when syncing files using the develop.watch configuration in docker-compose.yaml. I think it should be this way, because I don't want to specify those files in multiple places.

I've tested with a .dockerignore file in the root folder, in which it worked as expected, i.e. the files would not be synced into the container as described in https://docs.docker.com/compose/how-tos/file-watch/. I'd like that exact behavior, just working for the Dockerfile.dockerignore notation as well.

Steps To Reproduce

  1. Create a project with a docker-compose.yaml file similar to this one:
services:
    php-fpm:
        build:
            context: .
            dockerfile: .docker/php-fpm/Dockerfile
        develop:
            watch:
                - action: sync
                  path: .
                  target: /var/www
  1. Create a file .docker/php-fpm/Dockerfile.dockerignore which contains some files that should not be copied to the image/container
  2. Execute docker compose up --watch
  3. See that the files listed in .docker/php-fpm/Dockerfile.dockerignore are actually not in the started container (they won't be there)
  4. Edit one of the files listed in .docker/php-fpm/Dockerfile.dockerignore
  5. See that the file that has just been edited turns up in the started container (which it IMO shouldn't, because it is listed in .docker/php-fpm/Dockerfile.dockerignore)

Compose Version

Docker Compose version v2.28.1-desktop.1

Docker Environment

Client:
 Version:    27.0.3
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.15.1-desktop.1
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.28.1-desktop.1
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.32
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Alpha) (Docker Inc.)
    Version:  v0.0.14
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-desktop
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.25
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.3.0
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.10.0
    Path:     /Users/danielrotter/.docker/cli-plugins/docker-scout

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 27
 Server Version: 27.0.3
 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: 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: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae71819c4f5e67bb4d5ae76a6b735f29cc25774e
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.6.32-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 12
 Total Memory: 15.6GiB
 Name: docker-desktop
 ID: 0a75f2c7-3ac5-4689-8f94-8bb250084953
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/danielrotter/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions