Skip to content

Instantly share code, notes, and snippets.

@santi020k
Last active November 9, 2023 23:36
Show Gist options
  • Save santi020k/ad9e376dba65763b12021c7b755e363d to your computer and use it in GitHub Desktop.
Save santi020k/ad9e376dba65763b12021c7b755e363d to your computer and use it in GitHub Desktop.
Basic docker commands
# Notes
containerID # First 3 digits of the ID are usually sufficient
-it # Interactive mode
# Check Docker version
docker -v
# or
docker version
# Install an image
docker pull distribution # busybox and alpine are lightweight distributions, or the classic ubuntu
# Run a container
docker run distribution
# If you run a container with an image that is not available, Docker will download and run it.
# Run a container and remove it when execution is complete
docker run --rm distro
# Create a container without running it
docker create -it distribution command
# Create a container with a specified name
docker run -it --name=containerName distribution command
# Run a container with a command
docker run distribution command # a possible command is the classic 'echo helloWord'
# Stop a container
docker stop containerID
# Start a container
docker start containerID
# Attach to a container's console
docker attach containerID
# Execute commands in a container interactively (remaining in the console)
docker exec -it containerID command
# List images
docker images
# List active containers
docker ps
# List all containers
docker ps -a
# List all containers with full IDs
docker ps -a --no-trunc # normally Docker does not display full IDs
# Remove a container, as long as it is not running
docker rm containerID
# Remove all containers
docker rm $(docker ps -a -q)
# Better way to run a container and stay in the console
docker run -it distribution
# It will always run as the root user
# Create an image in Docker
docker commit -a "creator <[email protected]>" -m "message (version 1.0)" containerID imageName
# It will create an image based on the containerID
# It returns the ID of the new image
# Where to find images created by other developers
https://hub.docker.com/
# Search for images from the console
docker search search
# Search for images by score from the console
docker search -s 10 search # 10 is the desired score
# Delete an image
docker rmi imageID # No container can be using it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment