Start a container and map all ports
docker run -P image
Start a container in the background
docker run -d image
Start a container with an assigned hostname
docker run --hostname hostname_for_image image
Start a container with a dns entry
docker run --add-host hostname:ip image
Start a container and map a local directory into the container
docker run -v host-directory:target-directory image
Example: docker run -v ~/website:/var/www/html/ apache2
Start a container but change the entry point
docker run -it --entrypoint executable image Example: docker run -it --entrypoint bash nginx
Manage containers
Show a list of running containers
docker ps
Show a list of all containers
docker ps -a
Delete a container
docker rm container
Delete stopped container
docker container prune
Stop a running container
docker stop container
Start a stopped container
docker start container
Copy a file from a container to the host
docker cp container:source target Example: docker cp web:/index.html index.html
Copy a file from the host to a container
docker cp target container:source Example: docker cp index.html web:/index.html
Start a shell inside a running container
docker exec -it container executable Example: docker exec -it web bash
Rename a container
docker rename old-name new-name
Create an image out of a container
docker commit container
Manage images
Download an image
docker pull image
Upload an image to a repository
docker push image
Delete an image
docker rmi image
List all images
docker images
Delete dangling images
docker image prune
Delete all unused images
docker image prune -a
Build an image from a Dockerfile
docker build Directory
Tag an image
docker tag image newimage
Build and tag an image from a docker file
docker build -t image directory
Save an image to .tar file
docker save image > file.tar
Load an image from a .tar file
docker load -i file.tar
Info and stats
Show the logs for a container
docker logs container
Show stats of running container
docker stats
Show processes of a container
docker top container
Show installed docker version
docker version
Get detailed info about an object
docker inspect name
Show all modified files in container
docker diff container
Show mapped ports of a container
docker port container