loading...

docker : basic commands

zakiarsyad profile image Zaki Arrozi Arsyad ・2 min read

Docker info

check the version or if docker is already installed

$ docker --verison

show system information regarding docker installation

$ docker info

show stats of runnign container

$ docker stats

show container log

$ docker logs <CONTAINER_ID>

show processes of container

$ docker top <CONTAINER_ID>

show detailed info of container

$ docker inspect <CONTAINER_ID>

show modified files in a container

$ docker diff <CONTAINER_ID>

show mapped ports in a container

$ docker port <CONTAINER_ID>

Help / manual

list available commands

$ docker

manual for specific command

$ docker <COMMAND> --help

Run a new container

create a new container

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

// create from specific version
$ docker create <IMAGE[:TAG]>

start a container

$ docker start <CONTAINER_ID>

run (create and start) a new container

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

// create from specific version
$ docker run <IMAGE[:TAG]>

run in the background

$ docker run -d <IMAGE>

run and assign it a name

$ docker run --name <CONTAINER_NAME> <IMAGE>

run and map a port

$ docker run -p <HOST_PORT>:<CONTAINER_PORT> <IMAGE>

run and map all port

$ docker run -P <IMAGE>

run and assign a hostname

$ docker run --hostname <HOSTNAME> <IMAGE>

run and add a dns entry

$ docker run --add-host <HOSTNAME>:<IP> <IMAGE>

run and map a local dir

$ docker run -v <HOST_DIR>:<TARGET_DIR> <IMAGE>

run and change the entry point

$ docker run -it --executable <COMMAND> <IMAGE>

Manage Container

show list of all running container

$ docker ps

show list of all container

$ docker ps -a

stop a running container

$ docker stop <CONTAINER_ID>

kill a running container

$ docker kill <CONTAINER_ID>

start a stopped container

$ docker start <CONTAINER_ID>

restart a container

$ docker restart <CONTAINER_ID>

suspend a container

$ docker pause <CONTAINER_ID>

resume a container

$ docker unpause <CONTAINER_ID>

rename a container

$ docker rename <OLD_NAME> <NEW_NAME>

start shell inside a running container

$ docker exce -it <CONTAINER_ID> <COMMAND>

copy a file from host to container

$ docker cp <SOURCE> <CONTAINER_ID>:<DESTINATION>

copy a file from container to host

$ docker cp <CONTAINER_ID>:<SOURCE> <DESTINATION>

delete a container

$ docker rm <CONTAINER_ID>

destroy (kill + rm) a running container

$ docker rm -f <CONTAINER_ID>

delete all stopped containers

$ docker container prune

create an image out of container

$ docker commit <CONTAINER_ID>

Manage Images

download an image

$ docker pull <IMAGE[:TAG]>

upload an image to repository

$ docker push <IMAGE[:TAG]>

show list of images

$ docker images

build an image

$ docker build <DIRECTORY>

build and tag the image

$ docker build -t <IMAGE[:TAG]> <DIRECTORY>

tag an image

$ docker tag <SOURCE_IMAGE[:TAG]> <TARGET_IMAGE[:TAG]>

delete an image

$ docker rmi <IMAGE>

delete dangling images

$ docker image prune

delete all unused images

$ docker image prune -a

save an image to tar file

$ docker save <IMAGE> > <FILE.tar>

load an image from tar file

$ docker load -i <FILE.tar>

Posted on by:

Discussion

pic
Editor guide