DEV Community

Zaki Arrozi Arsyad
Zaki Arrozi Arsyad

Posted on

docker : basic commands

Docker info

check the version or if docker is already installed

$ docker --verison
Enter fullscreen mode Exit fullscreen mode

show system information regarding docker installation

$ docker info
Enter fullscreen mode Exit fullscreen mode

show stats of runnign container

$ docker stats
Enter fullscreen mode Exit fullscreen mode

show container log

$ docker logs <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

show processes of container

$ docker top <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

show detailed info of container

$ docker inspect <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

show modified files in a container

$ docker diff <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

show mapped ports in a container

$ docker port <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

Help / manual

list available commands

$ docker
Enter fullscreen mode Exit fullscreen mode

manual for specific command

$ docker <COMMAND> --help
Enter fullscreen mode Exit fullscreen mode

Run a new container

create a new container

// create from latest version
$ docker create <IMAGE>

// create from specific version
$ docker create <IMAGE[:TAG]>
Enter fullscreen mode Exit fullscreen mode

start a container

$ docker start <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

run (create and start) a new container

// create from latest version
$ docker run <IMAGE>

// create from specific version
$ docker run <IMAGE[:TAG]>
Enter fullscreen mode Exit fullscreen mode

run in the background

$ docker run -d <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and assign it a name

$ docker run --name <CONTAINER_NAME> <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and map a port

$ docker run -p <HOST_PORT>:<CONTAINER_PORT> <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and map all port

$ docker run -P <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and assign a hostname

$ docker run --hostname <HOSTNAME> <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and add a dns entry

$ docker run --add-host <HOSTNAME>:<IP> <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and map a local dir

$ docker run -v <HOST_DIR>:<TARGET_DIR> <IMAGE>
Enter fullscreen mode Exit fullscreen mode

run and change the entry point

$ docker run -it --executable <COMMAND> <IMAGE>
Enter fullscreen mode Exit fullscreen mode

Manage Container

show list of all running container

$ docker ps
Enter fullscreen mode Exit fullscreen mode

show list of all container

$ docker ps -a
Enter fullscreen mode Exit fullscreen mode

stop a running container

$ docker stop <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

kill a running container

$ docker kill <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

start a stopped container

$ docker start <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

restart a container

$ docker restart <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

suspend a container

$ docker pause <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

resume a container

$ docker unpause <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

rename a container

$ docker rename <OLD_NAME> <NEW_NAME>
Enter fullscreen mode Exit fullscreen mode

start shell inside a running container

$ docker exce -it <CONTAINER_ID> <COMMAND>
Enter fullscreen mode Exit fullscreen mode

copy a file from host to container

$ docker cp <SOURCE> <CONTAINER_ID>:<DESTINATION>
Enter fullscreen mode Exit fullscreen mode

copy a file from container to host

$ docker cp <CONTAINER_ID>:<SOURCE> <DESTINATION>
Enter fullscreen mode Exit fullscreen mode

delete a container

$ docker rm <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

destroy (kill + rm) a running container

$ docker rm -f <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

delete all stopped containers

$ docker container prune
Enter fullscreen mode Exit fullscreen mode

create an image out of container

$ docker commit <CONTAINER_ID>
Enter fullscreen mode Exit fullscreen mode

Manage Images

download an image

$ docker pull <IMAGE[:TAG]>
Enter fullscreen mode Exit fullscreen mode

upload an image to repository

$ docker push <IMAGE[:TAG]>
Enter fullscreen mode Exit fullscreen mode

show list of images

$ docker images
Enter fullscreen mode Exit fullscreen mode

build an image

$ docker build <DIRECTORY>
Enter fullscreen mode Exit fullscreen mode

build and tag the image

$ docker build -t <IMAGE[:TAG]> <DIRECTORY>
Enter fullscreen mode Exit fullscreen mode

tag an image

$ docker tag <SOURCE_IMAGE[:TAG]> <TARGET_IMAGE[:TAG]>
Enter fullscreen mode Exit fullscreen mode

delete an image

$ docker rmi <IMAGE>
Enter fullscreen mode Exit fullscreen mode

delete dangling images

$ docker image prune
Enter fullscreen mode Exit fullscreen mode

delete all unused images

$ docker image prune -a
Enter fullscreen mode Exit fullscreen mode

save an image to tar file

$ docker save <IMAGE> > <FILE.tar>
Enter fullscreen mode Exit fullscreen mode

load an image from tar file

$ docker load -i <FILE.tar>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)