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:version
docker 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:version
docker 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-world
docker 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-world
docker 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-world
docker 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 CONTAINER
tells what ports are open
Docker Run
docker run -d --name my-service
-p host's-port:container's-port
my-service
docker run -d --name my-service
-p host's-port:container's-port
my-service
-d
or--detach
: run container in detached/background mode and print container ID-p
or--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:8080
my-service
Docker Network
docker network create network-name
docker network create network-name
creates bridge type of network with name: network-name
docker network create -d overlay network-name
docker network create -d overlay network-name
creates overlay type of network with name: network-name
if
-d
is not specified the default network type is bridge
docker network ls
docker network ls
lists all the networks the Engine daemon
knows about
docker network ls --no-trunc
docker network ls --no-trunc
lists 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 NETWORK
attach a network to running container
docker network disconnect NETWORK
docker network disconnect NETWORK
detach a network to running container
Docker Volume
docker volume create hello
docker volume create hello
creates hello named local type of volume
docker volume ls
docker volume ls
lists all volumes
Docker Logs
docker logs CONTAINER
docker logs CONTAINER
retrieves logs present at the time of execution
docker logs -f CONTAINER
docker logs -f CONTAINER
follows logs output
docker logs --tail|-n CONTAINER
docker logs --tail|-n CONTAINER
number 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/sh
ordocker exec -i -t my-container /bin/sh
run a command in running container
-i
: keep STDIN open even if not attached-t
: allocate a pseudo-TTY
Last updated