Docker Cheat Sheet
docker run
: Runs a container from an image.docker start
: Starts a container that has been stopped.docker stop
: Stops a running container.docker restart
: Restarts a running container.docker rm
: Removes a container.docker rmi
: Removes an image.docker ps
: Lists all running containers.docker images
: Lists all images on the system.docker exec
: Runs a command in a running container.docker build
: Builds an image from a Dockerfile.docker pull
: Pulls an image from a registrydocker push
: Pushes an image to a registry.docker login
: Logs in to a registry.docker logout
: Logs out of a registry.docker cp
: Copies files or directories between a container and the host machine.docker volume
: Manages volumes for containers.docker network
: Manages networks for containers.
Example:
# Run a container from the image "myimage"
docker run -it myimage
# Start a container named "mycontainer"
docker start mycontainer
# Stop a container named "mycontainer"
docker stop mycontainer
# Remove a container named "mycontainer"
docker rm mycontainer
# Remove an image named "myimage"
docker rmi myimage
# List all running containers
docker ps
# Build an image from the Dockerfile in the current directory
docker build -t myimage .
# Pull an image named "myimage" from the "myregistry" registry
docker pull myregistry/myimage
# Push an image named "myimage" to the "myregistry" registry
docker push myregistry/myimage
Note: (Almost) Always use --rm
option while running the container to remove the container automatically when it exits.
#dockerfile #containers
Page last modified: 2024-11-13 09:17:00