Skip to content

Instantly share code, notes, and snippets.

@dkatz23238
Last active January 17, 2022 13:52
Show Gist options
  • Save dkatz23238/037948c31058c2c6c37e40dc0e56c634 to your computer and use it in GitHub Desktop.
Save dkatz23238/037948c31058c2c6c37e40dc0e56c634 to your computer and use it in GitHub Desktop.
Docker training 2022 scripts
# Run a container
docker run -it python:latest bash
# or
# will start the container using latest CMD or ENTRYPOINT
docker run -it python:latest
# Run dettach mode, if you don't the shell session will be attaced to the containers lifecycle
docker run -it -d python:latest
# Run with env --rm will remove the container upon exit of last proccess.
docker run --rm -it -e TRAINING_SESSION=DOCKER python:latest bash
# Create a directory to map a volume to and use in the container
mkdir /tmp/volume_map/
# You can map any directory on the host into the container and set its location to any valid path
docker run -it --rm -e PATH_MAP=/mapped_volume -v /tmp/volume_map:/mapped_volume python:latest bash
# Create a new network
docker network create docker-training
docker run --rm --network docker-training --name redis -e ALLOW_EMPTY_PASSWORD=yes bitnami/redis:latest
docker run --name redis-client --rm -it --network docker-training python:latest bash
# python -m pip install redis
# Ipython
# r = redis.Redis(host='redis', port=6379, db=0)
# r.set("myvariable","myvalue")
# print(r.get("myvariable"))
# View images
docker image ls
# Build a new image
docker build -f Dockerfile name:tag
# Stop a running container
docker stop CONTAINERID
# Remove container
docker rm CONTAINERID
# Connect to a running container
docker exec -it bash DOCKER_CONTAINER_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment