zoshigayan
zoshigayan

Reputation: 41

docker-compose volume not synced

PROBLEM

I use docker-compose for development with Python/Flask. I want my host codebase to sync with one inside docker container but not...

SITUATION

My working directory structure is below:

.
├── Dockerfile
├── docker-compose.yml
├── app.py
└── requirements.txt

I made bind mount from host's current directory to container's /app.

Dockerfile:

FROM python:3.7.3-alpine3.9

WORKDIR /app

COPY requirements.txt requirements.txt

RUN pip install --upgrade pip && \
  pip install -r requirements.txt

COPY . .

CMD gunicorn -b 0.0.0.0:9000 -w 4 app:app

docker-compose.yml:

version: '3'
services:
  web:
    build: .
    ports:
      - "4649:9000"
    volumes:
      - .:/app

When I access http://localhost:4649 I can see correct response so Docker container is working well. However response don't update when I change app.py.

I inspected the container and the result is below

"Mounts": [
            {
                "Type": "bind",
                "Source": "/Users/emp-mac-zakiooo/dev/jinja-pwa",
                "Destination": "/app",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

It looks very right so I have no idea about this problem 😇

Upvotes: 3

Views: 12450

Answers (2)

zoshigayan
zoshigayan

Reputation: 41

OMG I found my files are correctly synced but gunicorn cached them so added --reload to CMD in Dockerfile, and finally it fixed. Thank you for helping and soooo sorry for my foolishness...!

Upvotes: 1

Raphael Costa
Raphael Costa

Reputation: 86

You could achieve that by doing the following:

volumes:
    mount:
        driver: local
        driver_opts:
          type: nfs
          o: addr=host.docker.internal,rw,nolock,hard,nfsvers=3
          device: ":${PWD}/path"

In your volume declaration within a service, you can do the following:

version: '3'
services:
  web:
    build: .
    ports:
      - "4649:9000"
    volumes:
      - mount:/app

Add the following to /etc/exports to enable docker access to your nfs volumes <path to $WORKSPACE> 127.0.0.1 -alldirs -mapall=0:80 once it's there you need to run sudo nfsd restart to include your changes.

if ever docker-compose stops responding when using NFS, restarting docker usually fixes it

I hope that this helps!

Upvotes: 0

Related Questions