diff --git a/docker/create-image.md b/docker/create-image.md index 038510fe1..b283c4ab2 100644 --- a/docker/create-image.md +++ b/docker/create-image.md @@ -607,6 +607,19 @@ docker container cp chronos:/opt/dates.txt . docker container stop chronos ``` +## Docker: Mounting host directory +{id: docker-mounting-host-directory} + +``` +$ docker run -it --rm -v $(pwd):/opt/ mydocker + +# cd /opt +# ls -l +``` + +The `-v HOST:CONTAINER` will mount the `HOST` directory of the home operating system to the `CONTAINER` directory in the Docker container. + + ## Exercies 2 {id: exercise-2} diff --git a/docker/examples/python-5/Dockerfile b/docker/examples/old-python-5/Dockerfile similarity index 100% rename from docker/examples/python-5/Dockerfile rename to docker/examples/old-python-5/Dockerfile diff --git a/docker/examples/python-3/curl.py b/docker/examples/old-python-5/curl.py similarity index 100% rename from docker/examples/python-3/curl.py rename to docker/examples/old-python-5/curl.py diff --git a/docker/examples/python-4/Dockerfile b/docker/examples/python-4/Dockerfile deleted file mode 100644 index 4c42cdab6..000000000 --- a/docker/examples/python-4/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM python:3.8 -RUN pip3 install requests -COPY curl.py /opt/ diff --git a/docker/examples/python-curl-dev/Dockerfile b/docker/examples/python-curl-dev/Dockerfile new file mode 100644 index 000000000..55acb3f50 --- /dev/null +++ b/docker/examples/python-curl-dev/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.8 +RUN pip3 install requests +# COPY curl.py . +# ENTRYPOINT ["python3", "curl.py"] diff --git a/docker/examples/python-4/curl.py b/docker/examples/python-curl-dev/curl.py similarity index 100% rename from docker/examples/python-4/curl.py rename to docker/examples/python-curl-dev/curl.py diff --git a/docker/examples/python-3/Dockerfile b/docker/examples/python-curl/Dockerfile similarity index 100% rename from docker/examples/python-3/Dockerfile rename to docker/examples/python-curl/Dockerfile diff --git a/docker/examples/python-5/curl.py b/docker/examples/python-curl/curl.py similarity index 100% rename from docker/examples/python-5/curl.py rename to docker/examples/python-curl/curl.py diff --git a/docker/old.md b/docker/old.md index 26c77e2a1..24d9cba7d 100644 --- a/docker/old.md +++ b/docker/old.md @@ -47,4 +47,17 @@ $ docker history mydocker2 ``` ![](examples/dock/history_mydocker2.out) +## Distribute command-line script and include command +{id: distribute-command-line-script-and-include-command} + +![](examples/old-python-5/Dockerfile) + + +``` +$ docker build -t mydocker . + + +$ docker run --rm mydocker https://code-maven.com/slides +``` + diff --git a/docker/python.md b/docker/python.md index 2d8c72297..908977714 100644 --- a/docker/python.md +++ b/docker/python.md @@ -1,81 +1,44 @@ # Python with Docker -{id: python-with-docker} +{id: python} ## Python CLI in Docker - curl.py {id: python-cli-in-docker-code} -![](examples/python-3/curl.py) +![](examples/python-curl/curl.py) -## Python CLI in Docker - curl.py +## Python CLI in Docker - Dockerfile {id: python-cli-in-docker-dockerfile} - -![](examples/python-3/Dockerfile) +![](examples/python-curl/Dockerfile) ``` $ docker build -t mydocker . -``` -``` -docker run --rm mydocker https://httpbin.org/get +$ docker run --rm mydocker https://httpbin.org/get ``` +* [https://httpbin.org/](https://httpbin.org/) + {aside} This is a simple implementation of a curl-like script in Python. Wrapped in a Docker container. Firs build the container and then you can run the script. {/aside} -## Docker: Mounting host directory -{id: docker-mounting-host-directory} - -``` -$ docker run -it --rm -v /home/gabor/work/slides/docker/examples/python-3:/opt/ mydocker - -$ docker run -it --rm -v c:\Users\Gabor Szabo\work\slides\docker\examples python-3:/opt/ mydocker - -# cd /opt -# ls -l -``` - -The `-v HOST:CONTAINER` will mount the `HOST` directory of the home operating system to the `CONTAINER` directory in the Docker container. - -``` -# ./curl.py -I https://code-maven.com/slides -``` - -* You can edit the file on your host system (with your IDE) and run it on the command line of the Docker container. - - -* A better way to mount the current working directory, at least on Linux and OSX - -``` -docker run -it --rm -v $(pwd):/opt/ mydocker -``` -## Distribute command-line script -{id: distribute-command-line-script} +## Docker: Python Development mode with mounted directory +{id: docker-development-mode-with-mounted-directory} - -![](examples/python-4/Dockerfile) +![](examples/python-curl-dev/Dockerfile) ``` $ docker build -t mydocker . -$ docker run --rm mydocker /opt/curl.py https://code-maven.com/slides -``` - -## Distribute command-line script and include command -{id: distribute-command-line-script-and-include-command} - -![](examples/python-5/Dockerfile) - - +$ docker run --rm -v $(pwd):/opt/ mydocker python /opt/curl.py https://httpbin.org/get ``` -$ docker build -t mydocker . +* You can edit the file on your host system (with your IDE) and run it on the command line of the Docker container. -$ docker run --rm mydocker https://code-maven.com/slides -``` +* A better way to mount the current working directory, at least on Linux and OSX ## Flask application