Docker commands

A container is an instance of an image. An image is created by running a recipe.

Install : https://docs.docker.com/engine/installation/linux/docker-ce/debian/

Check this docker hub repo: https://hub.docker.com/explore/

List of useful docker commands:
# Show available docker images
docker images
# Download image
docker pull debian
# Delete image
docker image rm <IMAGE_ID>
# Show containers
docker ps -a
# Create container from image
docker run -it --name="<CONTAINER_NAME>" <IMAGE_ID>
# You can forward ports with -p <HOST_PORT>:<CONTAINER_PORT>
# You can mount folders with -v /host/dir:/container/dest
# Delete container
docker rm <CONTAINER_ID>
# Run image interactively (creates container and removes it on exit)
docker run -it --rm=true <IMAGE_ID>
# Build docker image from Dockerfile, will be accessible by name <IMAGE_NAME>
docker build -t <IMAGE_NAME> .
# Stop container
docker stop <CONTAINER_ID>
# Start existing container
docker start <CONTAINER_ID>
# List volumes
docker volume ls
# Rename container
docker rename <CURRENT_CONTAINER_NAME> <NEW_CONTAINER_NAME>
# Add docker network
docker network create --subnet=172.18.0.0/16 <NETWORK_NAME>
# List docker networks
docker network list
# Delete docker network
docker network remove <NETWORK_ID>
# Run image (by starting new container) with given IP in given network
docker run --net <NETWORK_NAME> --ip 172.18.0.2 -it --rm=true <IMAGE_NAME>
# Run image (by starting new container) container with given host name
docker run -it --rm=true -h <HOST_NAME> <IMAGE_NAME>
# Rename container
docker rename <CONTAINER_ID> <NEW_CONTAINER_NAME>

# Update a running container to auto-restart
docker update --restart=always <CONTAINER_ID>

# Save docker image to file:
docker save -o <PATH_TO_FILE> <IMAGE_NAME>

# Load docker image from file:
docker load -i <PATH_TO_FILE>

# This seems like a nice UI for docker:
docker run -d -p 10086:10086 -v /var/run/docker.sock:/var/run/docker.sock tobegit3hub/seagull
# Then go to http://127.0.0.1:10086

To cleanup a debian docker image you can:

# To undo apt-get update you can:
rm -Rf /var/lib/apt/lists/*