Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Docker: Python Development mode with mounted directory

FROM python:3.8
RUN pip3 install requests
# COPY curl.py .
# ENTRYPOINT ["python3", "curl.py"]
$ docker build -t mydocker .

$ docker run --rm -v $(pwd):/opt/ mydocker python /opt/curl.py  https://httpbin.org/get
  • --rm to remove the container when we stopped it.

  • -v $(pwd):/opt/ to map the current directory on the host system to the /opt directory inside the container

  • mydocker is the name of the image

  • After that we can any python program.

  • You can edit the file on your host system (with your IDE) and run it on the command line of the Docker container.

  • This works on Linux and Mac OSX. On Windows you might need to spell out the current working directory yourself.