In this post, I show some useful docker commands that you may be less familiar with them and they make your life easier as a developer. Lets begin with build command:
docker build -f path/to/file/Dockerfile -t image-name . -f lets you specify the path to Dockerfile.
Tag or rename image
docker tag old-image-name new-image-name You Can use image id rather than image name:
docker tag 0e5574283393 new-image-name Save image:
docker save image-name -o output-image-name If the image name contains /:
docker save image-name/image-name > output-image-name Load image:
docker load --input output-image-name Remove images that name starting with myimage
docker rmi $(docker image ls 'myimage*' -q) Delete images whose names starting with myimage.
Delete all untagged images
docker rmi $(docker images -f "dangling=true" -q) Delete all images (warning)
docker rmi -f $(docker images -q) Start all stopped containers
docker start $(docker ps -aq) Stop all running containers
docker stop $(docker ps -q) Delete all containers
docker rm $(docker ps -aq) or docker container stop $(docker container ls –aq) && docker system prune –af ––volumes Delete any resources — images, containers, volumes, and networks — that are dangling (warning)
docker system prune Delete any stopped containers and all unused images (warning)
docker system prune -a Copy file to container
docker cp ./path/to/file.ext container-name:/path/to/destination/inside/container Build an image from running container
docker commit container-name image-name:tag Mount file to a container
docker run -v /path/to/file/appsettings.json:/app/appsettings.json --name my-image image-name Get into a Docker container's shell
docker exec -it container-name /bin/bash Display volumes with mounted path
docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Mounts}}' Delete volumes whose names starting with myvloume.
docker volume rm $(docker volume ls --filter name=myvloume -q) Delete dangling volumes
docker volume ls -f dangling=true Build docker-compose from several files
docker-compose -f docker-compose.yml -f docker-compose.dev.yml build Scale a service
docker-compose scale service-name=2 Command that contains $ could be executed on windows command prompt (cmd), use PowerShell instead

Top comments (0)