-
Create image using current directory’s Dockerfile
docker build -t image-name .
-
List images
docker images
-
Create new container from specified image
docker run image-name
-
Assign a name to the container
docker run --name nick-name image-name
-
Run image with an entry point | override existing entrypoint
docker run image-name cmd
docker run image-name --entrypoint cmd
-
Run image in interactive mode
docker run -it image-name
-
Run image in detached mode
docker run -d image-name
-
Run image mapping container's port to the host
docker run -p host-port:container-port image-name
-
List running containers
docker ps
-
List all containers
docker ps -a
-
Stop one or more running containers
docker stop containerId
-
Start one or more stopped containers
docker start containerId
-
Fetch the logs of a container
docker logs containerId
-
Fetch and follow log output of a container
docker logs -f containerId
-
Run a command in a running container in interactive mode
docker exec -it containerId cmd
-
Copy files/folders from container to local filesystem
docker cp containerId:/workdir/file.ext .
-
Copy files/folders from local filesystem to container
docker cp file.ext containerId:/workdir/
-
Remove container
docker rm containerId
-
Remove running container
docker rm -f containerId
-
Remove all running and stopped containers
docker rm -f $(docker ps -a -q)
-
Creates a new volume that containers store data
docker volume create volume-name
-
Display detailed information on one or more volumes
docker volume inspect volume-name
-
List volumes
docker volume ls
-
Create a volume and then configure the container to use it
docker run -v volume-name:/dir/dir container-name
-
Create mapping between dir in host and container
docker run -v $(pwd):/workdir container-name
-
Create tag to the image while building
docker build -t image-name:tag .
-
Create tag to the image after building
docker image tag src-image:latest dst-image:tag
-
Save one or more images to a tar archive
docker image save -o image-name.tar image-name:tag
-
Load an image from a tar archive
docker image load -i image-name.tar
-
Remove one or more images
docker image rm image-name
docker rmi image-name
-
Remove all images
docker system prune -a
-
Remove all stopped containers
docker container prune
-
Remove all dangling images
docker image prune
-
Remove all unused containers, networks, dangling and unreferenced images
docker system prune