Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active September 3, 2018 07:21
Show Gist options
  • Save xbalaji/a6a0afc87833874f6b7452414eb4bd82 to your computer and use it in GitHub Desktop.
Save xbalaji/a6a0afc87833874f6b7452414eb4bd82 to your computer and use it in GitHub Desktop.
docker-python-cheatsheet
# run a python 2.7 in a docker container, debian linux, apt works
docker run --name py27 -d -t python:2.7
# exec bash in the docker container
docker exec -i -t py27 /bin/bash
# run a container with mounting directory, mount volume should be absolute path
docker run --name py27 -d -t -v ~/all/xb-all/utils:/utils python:2.7
# stop and remove a running container
docker stop py27
docker rm py27
# find running containers
docker ps -a
# run python 2.7 in alpine linux (minimal os distribution)
docker run --name py27alphine -t -d python:2.7-alpine
docker exec -i -t py27alpine /bin/sh # there is no bash in alpine
# mount volume, re-direct ports
docker run --name py27alpine -t -d -v ~/all/xb-all/utils:/utils -p 8080:8000 python:2.7-alpine
# now run a simple python webserver, in daemonized mode
docker exec -d py27alpine python -m SimpleHTTPServer
# or running python after exec a shell
docker exec -t py27alpine -i /bin/sh
# curl http://localhost:8080 <--- reaches the 8000 port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment