0

I am trying to setup my python environment in docker.

My docker image is like this:

FROM python:2.7
# updating repository
RUN apt-get update

RUN mkdir /usr/src/app

WORKDIR /usr/src/app

COPY requirements.txt requirements.txt

RUN pip install --no-cache -r requirements.txt

EXPOSE 8888

COPY . .

CMD ["python", "test.py"]

with this build command:

docker build -t ml-python-2.7 .

After image is built, I ran

docker run -it --rm --name ml-container  ml-python-2.7 python test.py

My sample test.py

print('test here')

It works when I first run this command.

docker run -it --rm --name ml-container  ml-python-2.7 python test.py

but after I change the test.py to print('second test') and run the above command again, it still output test here.

How do I make sure it updates automatically or if there is more elegant way to do this?

Thanks!

4
  • 3
    Are you simply modifying test.py in the current directory? The running docker container can't see inside your current directory. Commented Mar 8, 2018 at 6:27
  • 1
    either mount the current directory in docker ( use -v option), get in to bash inside docker and edit the file Commented Mar 8, 2018 at 6:30
  • @vumaasha Could you give me an example to set it up? Commented Mar 8, 2018 at 6:35
  • @Jwqq check my answer Commented Mar 8, 2018 at 6:54

1 Answer 1

1

Docker does not store the changes you are making to files inside the container unless you commit it. If you want it to do so, you need to do a Docker Commit like:

docker commit <CONTAINER NAME HERE>

Or you could mount a local folder to the docker image like this:

docker run -ti -v ~/folder_in_host:/var/log/folder_in_container <IMAGE NAME HERE>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.