docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.71k stars 5.19k forks source link

[BUG] Changes in files within docker container aren't reflected #10358

Open SalihBorucu opened 1 year ago

SalihBorucu commented 1 year ago

Description

I actively work on this project for hours and everything works fine. Then at some point, the code changes I make on the files are ignored. Sometimes it is on all files and sometimes it is on a single file.

I was frustrated so reformatted the whole macbook just to resolve this, however, even after the reformat and reinstalling everything still facing the same issues.

The same project is also maintained by two other colleagues with exact same DockerFile and docker-compose.yaml and they have never faced this issue. One uses an M1 macbook other uses an identical with mine and we have almost no difference with the processes and applications we use.


The changes to the code are reflected if I docker compose down then docker compose up again.


To debug, I used docker compose exec app bash into the container and used less to check if changes can be seen, the changes weren't there. However, when I less same file outside of the docker container, changes are there.

So I experimented and used nano to change the file within the container and I could see the changes if I used less after but, when I run the code the changes weren't there.

Somehow my old code is cached somewhere, yet I have no idea where.


Here is the app part of my docker-compose if that helps

version: '3.8'
services:
  app:
    build:
      context: ./docker/app
      dockerfile: Dockerfile
    image: my-app/app
    ports:
      - '${LARAVEL_WEBSOCKETS_PORT:-6001}:${LARAVEL_WEBSOCKETS_PORT:-6001}'
      - "80:80"
      - "8000:8000"
    volumes:
      - .:/var/www/my-app

However, as I said exact same docker-compose file works for everyone else.


I know it is a really vague issue but I can't find a way to re-create this since it doesn't even happen to my colleagues and because it happens to me occasionally.

If someone could even point me in the right direction to debug this it would be much appreciated.

Also, open to any wild theories and workarounds since I am completely out of ideas.

Thank you


My current version of Docker Desktop is: 4.17.0 (99724) Using Macbook 2019 - Ventura

Steps To Reproduce

No response

Compose Version

Docker Compose version v2.15.1
Docker Compose version v2.15.1

Docker Environment

lient:
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.3)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.1.0)
  extension: Manages Docker extensions (Docker Inc., v0.2.18)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.25.0)
  scout: Command line tool for Docker Scout (Docker Inc., v0.6.0)

Server:
 Containers: 3
  Running: 3
  Paused: 0
  Stopped: 0
 Images: 19
 Server Version: 20.10.23
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  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 logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux 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: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.674GiB
 Name: docker-desktop
 ID: 54ZT:D2ZP:JSXM:AIIS:LZQP:VEUM:4VIO:HG62:JRVK:2CWN:YWKY:RUIN
 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
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

ndeloof commented 1 year ago

IIUC you don't see changes made on host on bind mounted .:/var/www/my-app ? This sounds like a Docker Desktop issue we can't address from docker compose :'(

In the meantime you could give compose watch a try and get file sync-ed into your development container: remove bind mount and add a x-develop section:

services:
  app:
    build:
      context: ./docker/app
      dockerfile: Dockerfile
    image: my-app/app
    ports:
      - '${LARAVEL_WEBSOCKETS_PORT:-6001}:${LARAVEL_WEBSOCKETS_PORT:-6001}'
      - "80:80"
      - "8000:8000"
    x-develop:
      watch:
        path: .
        action: sync

then run docker compose alpha watch

SalihBorucu commented 1 year ago

@ndeloof Thank you for this suggestion, I am unable to use alpha commands "unknown docker command: "compose alpha"

Is there something extra I need to change to enable experimental commands?

ndeloof commented 1 year ago

this command is included in recent release only

phpguru commented 1 year ago
volumes:
      - .:/var/www/my-app

You are bind mounting files into your container @SalihBorucu - turn this off/comment out and instead add

COPY ./ /var/www/my-app

to your Dockerfile, and rebuild the container. Use with the latest Docker Desktop and docker compose with x-develop : watch : sync as @ndeloof says. Docker compose version 2.17+

Note this is not the same as rebuilding the container when files are changed.

What File System option do you have selected in Docker Desktop General Settings? Use VirtioFS on MacOS for better performance.

These settings have been a total game changer for us. 90%+ performance increase on MacOS and large PHP monolith, 48K files, 900K loc, 48mb repo. I wrote it up and linked to the original blog post here.