Rajesh Chamarthi
Rajesh Chamarthi

Reputation: 18818

docker-compose volumes with a custom docker file

I am trying to mount my code directory using docker volume, but unable to do so. Here's the relevant section of my docker-compose file.

web:
  build: ./web
  dockerfile: Dockerfile
  links:
    - db:db
    - elasticsearch:elasticsearch
  volumes:
    - ./web:/usr/src/app

web folder has a DockerFile with the following instructions.

FROM python:2.7

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt

docker-compose up is working without any issues, but I don't see any volumes after start up.

root@test-new:/home/django/test# docker inspect test_web | grep -i volume
        "Volumes": null,
        "Volumes": null,

Here's the rest of my stack, if that is relevant.

elasticsearch
nginx
postgres db

Upvotes: 1

Views: 617

Answers (1)

Rajesh Chamarthi
Rajesh Chamarthi

Reputation: 18818

The following syntax works.

volumes: - ${PWD}/web:/usr/src/app

web:
  build: ./web
  dockerfile: Dockerfile-aside
  links:
    - db:db
    - elasticsearch:elasticsearch
  volumes:
    - ${PWD}/web:/usr/src/app
  env_file: .env

One of the reasons the earlier migrations were not being copied is because I was running the code inside a new container, instead of the container that is currently up.

Instead of

docker-compose run --rm web /bin/bash

When I tried

docker exec -it my_container_name web /bin/bash

And then run the migrate command, the newly generated database migration commands are not present on the source directory. It would be ideal to use docker-compose exec, but the current version I am using is below 1.7, so I am using the above interim solution in the mean time.

https://github.com/d11wtq/dockerpty/pull/48

Upvotes: 1

Related Questions