Command

docker run nginx # run nginx, auto download if not found
docker ps
docker ps -a # all
docker stop ContainerId
docker rm ContainerId
docker images # list available images
docker rmi nginx # remove images
docker pull nginx # download image but not run
docker exec container_name command
	docker exec ubuntu cat /etc/hosts

Images

docker pull <img>
# docker pull ubuntu
docker images # list images

run/start

docker run kodekloud/simple-webapp # run a webserver in attach mode
docker run -d kodekloud/simple-webapp # detach mode
docker attach ContainerId # re-attach the container
docker run -it centos bash # run bash in centos, then execute bash and auto login
docker run -it --name testbox ubuntu bash
docker start -ai testbox # start existing container

ps

docker ps # show running containers
docker ps -a # show all containers

Check version

docker --version
docker compose version

Detach

# default
<ctrl+p> <ctrl+q>
# set detach keys when starting a container
docker run --detach-keys="ctrl-],ctrl-]" -it myimage