Docker CLI Commands
Some most frequently used Docker CLI commands
Docker Build
docker build -t repository-name:version .
docker build -t repository-name:version .docker build -t my-service:latest .
docker build -t registry/repository-name:version .
docker build -t registry/repository-name:version .docker build -t registry.azurecr.io/my-service:latest .
docker build -t repository-name-1:version -t repository-name-2:version .
docker build -t repository-name-1:version -t repository-name-2:version .docker build -t my-service-1:1.0.0 -t my-service-2:1.0.0 .
Docker Tag
docker tag exiting-repository-name:version new-repository-name:version
docker tag exiting-repository-name:version new-repository-name:versiondocker tag my-service:latest registry.azurecr.io/my-service:latest
Docker Push
docker push registry/new-repository-name:version
docker push registry/new-repository-name:versiondocker push registry.azurecr.io/my-service:latest
Docker Image
List Images
docker images
docker images -a
docker image ls
docker image ls -a
Remove Image(s)
docker rmi <image-id(s) | image-name(s)>
docker rmi <image-id(s) | image-name(s)>docker rmi hello-worlddocker rmi hello-world, order-service, 0706874044f0
Remove all images
docker rmi $(docker images -aq)
docker rmi $(docker images -aq)Docker Container
List Containers
docker ps
docker ps -a
Stop Container(s)
docker stop <container-id(s) | container-name(s)>
docker stop <container-id(s) | container-name(s)>docker stop hello-worlddocker stop hello-world, order-service, item-service
docker stop $(docker ps -aq)
docker stop $(docker ps -aq)Remove Container(s)
docker rm <container-id(s) | container-name(s)>
docker rm <container-id(s) | container-name(s)>docker rm hello-worlddocker rm hello-world, order-service, item-service
Remove all containers
docker rm $(docker ps -aq)
Look what's happening inside container from outside
docker container top CONTAINER
docker container inspect CONTAINER
docker container stats CONTAINER [CONTAINER...]
Look what's happening inside container from inside
docker container run -it --name nginx -p 80:80 nginx bash
docker container run exec -it nginx bash
docker container port CONTAINER
docker container port CONTAINERtells what ports are open
Docker Run
docker run -d --name my-service-p host's-port:container's-portmy-service
docker run -d --name my-service-p host's-port:container's-portmy-service-dor--detach: run container in detached/background mode and print container ID-por--publish: bind outbound port to inbound port outbound:inbound i.e. 80:8080--name: assign a name to the containerdocker run -d --name my-service-p 80:8080my-service
Docker Network
docker network create network-name
docker network create network-namecreates bridge type of network with name: network-name
docker network create -d overlay network-name
docker network create -d overlay network-namecreates overlay type of network with name: network-name
if
-dis not specified the default network type is bridge
docker network ls
docker network lslists all the networks the Engine daemon knows about
docker network ls --no-trunc
docker network ls --no-trunclists all the networks with full network ID
docker network inspect network1 [network2 network3 ...]
docker network inspect network1 [network2 network3 ...]returns information about one or more networks
docker network connect NETWORK
docker network connect NETWORKattach a network to running container
docker network disconnect NETWORK
docker network disconnect NETWORKdetach a network to running container
Docker Volume
docker volume create hello
docker volume create hellocreates hello named local type of volume
docker volume ls
docker volume lslists all volumes
Docker Logs
docker logs CONTAINER
docker logs CONTAINERretrieves logs present at the time of execution
docker logs -f CONTAINER
docker logs -f CONTAINERfollows logs output
docker logs --tail|-n CONTAINER
docker logs --tail|-n CONTAINERnumber of lines to show from the end of the logs
Docker Inspect
docker inspect NAME|ID [NAME|ID...]
docker inspect NAME|ID [NAME|ID...]returns low-level information of docker objects
Docker exec
docker exec [OPTIONS] CONTAINER COMMAND [ARGS...]
docker exec [OPTIONS] CONTAINER COMMAND [ARGS...]docker exec -it my-container /bin/shordocker exec -i -t my-container /bin/shrun a command in running container
-i: keep STDIN open even if not attached-t: allocate a pseudo-TTY
Last updated