0

I have the following Dockerfile for a django app I am building

# base image to be used
FROM python:3.6
# The enviroment variable ensures that the python output is set straight
# to the terminal with out buffering it first
ENV PYTHONUNBUFFERED 1

# create root directory for our project in the container
#RUN mkdir /code

# Set the working directory to the created dir
WORKDIR /code

# add the requiremnets file to the working dir
COPY requirements.txt /code/

#instal the requirements (install before adding rest of code to avoid rerunning this at every code change-built in layers)
RUN pip3 install -r requirements.txt

# Copy the current directory contents into the container at /music_service
COPY . /code/

#set environments to be used
ENV AUTHOR="Mokgadi Rasekgala "

EXPOSE 8000

VOLUME /code

#run the service docker app
CMD /code/start.sh

when i build the file and run it using the following command

docker run -it -p 8000:8000 <image>

the volume does not seem to be mounted on /code directory

I also tried running it as

docker run -it -v my-vol:/code -p 8000:8000 <image>

but also still does not recognise changes i make to view without first building

As there something I am missing on how to define the Volume. I am trying to get the changes to be visible without having to build and run again

  • Have you tried with bind mounted directories? IMO named/anonymous volumes doesn't seem to fit your usecase. – codestation Mar 22 '19 at 17:42
  • Possible duplicate of [Understanding "VOLUME" instruction in DockerFile](https://stackoverflow.com/questions/41935435/understanding-volume-instruction-in-dockerfile) – David Maze Mar 22 '19 at 18:12
  • You can never get this effect without specifying the host path with a `docker run -v` option (and hiding basically everything the Dockerfile does). The `VOLUME` directive is unnecessary and has only confusing side effects here. – David Maze Mar 22 '19 at 18:13

0 Answers0