{id: python}
{id: python-cli-in-docker-code}
{aside}
This is a command line script, a very basic implementation of curl in Python. In order to run this we need Python and the requests
package to be installed.
{/aside}
{id: python-cli-in-docker-dockerfile}
$ docker build -t mydocker .
$ docker run --rm mydocker https://httpbin.org/get
{aside} This is a simple implementation of a curl-like script in Python. Wrapped in a Docker container. First build the container and then you can run the script. {/aside}
{id: docker-development-mode-with-mounted-directory}
$ 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.
{id: flask-application}
{aside} In this simple Flask web application we have 3 files. app.py, a template, and the requirements.txt {/aside}
{id: flask-development}
$ docker build -t mydocker .
$ docker run -it --name dev --rm -p5001:5000 -v $(pwd):/opt/ mydocker
-
-it
to be in interactive mode so we can see the log on the command line and we can easily stop the development container. -
--name dev
we set the name of the container to bedev
in case we would like to access it. -
--rm
remove the container after it is finished. -
-p5001:5000
map port 5001 of the host computer to port 5000 of the container. -
-v $(pwd):/opt/
map the current working directory of the host to /opt in the container. -
Access via http://localhost:5001/
{id: flask-uwsgi}
{id: flask-with-redis}
{id: docker-compose-redis-flask}
pip install docker-compose
docker-compose up
{id: python-flask-mongodb}
{id: docker-compose-python-flask-mongodb}
pip install docker-compose
docker-compose up
{id: python-flask-and-pulsar}
docker run -it -p 6650:6650 -p 8080:8080 apachepulsar/pulsar:2.4.1 bin/pulsar standalone
docker build -t mydocker .
docker run --rm -it mydocker bash
{id: python-and-pulsar}
Run:
docker-compose up
and then check the pulsar.log file
{id: flask-uwsgi-nginx}
Using https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/
docker build -t myapp .
docker run -it --rm -p5001:80 myapp