Docker Community Forums

Share and learn in the Docker community.

Docker container doesn't starts after changing host directory

I have a django app which i’m dockerizing. Below is the docker-compose.yml file (Only django part is given here)

 web:
    build: .
    command: python ./webapp/server.py
    restart: always
    volumes:
      - .:/code
      - ./webapp/static:/static
    networks:
      - nginx_network
      - couchserver_network
      - dummyapi_flaskapp_network

when i change the name of the host directory from where it is run, i’m getting the following error : python: can't open file './webapp/server.py': [Errno 2] No such file or directory
I have copied the host directory to image using :

RUN mkdir /code
WORKDIR /code
COPY . /code/

So after renaming my host directory why python is unable to find the server.py file as it is available in containers code directory.

I’m novice in docker and have little or no knowledge in volumes. Any help is really appreciated

Looking at the docker-compose.yml you’ve linked to, I don’t see any volume entry. Without that, there’s no connection possible between the files on your host and the files inside the container. You’ll need a docker-compose.yml that includes a volume entry, like:

version: ‘2’

services:

angular-seed:
build:
context: .
dockerfile: ./.docker/angular-seed.development.dockerfile
command: npm start
container_name: angular-seed-start
image: angular-seed
networks:
- dev-network
ports:
- ‘5555:5555’
volumes:
- .:/home/app/angular-seed

networks:
dev-network:
driver: bridge
Docker-machine runs docker inside of a virtual box VM. By default, I believe c:\Users is shared into the VM, but you’ll need to check the virtual box settings to confirm this. Any host directories you try to map into the container are mapped from the VM, so if your folder is not shared into that VM, your files won’t be included.

With the IP, localhost works on Linux hosts and newer versions of docker for windows/mac. Older docker-machine based installs need to use the IP of the virtual box VM.