Popular docker cmds Flashcards
docker run -it ubuntu:latest bash
create a container with the latest ubuntu image running an interactive bash shell
How to list all active running containers
docker ps
how to see stopped containers
docker ps -a
docker run –rm “IMAGE NAME/ID”
remove the container after stopping, otherwise container will remain
How to attach/connect to a running container
docker attach docker run –rm “CONTAINER NAME/ID”
entering and exiting a bash container will shutdown the container
how to list last container closed
docker ps -l
how to name a new image?
docker tag “ID” “NEW IMAGE NAME”
How to commit new changes to a container to a new image and rename the new image
docker commit “CONTAINER NAME/ID”
This will create a new image, but with no name.
The original container will continue unaffected
will return a large number, that can be used to name the image:
docker tag <> <>
How to run docker with an interactive terminal?
docker run -it
How to run a detached container
Use -d flag with run
docker run -d <>
How to exit an attached container without stopping it
CTRL p CTRL q
How to start a new process in an existing container?
docker exec -ti <> <>
example:
docker exec -it <> bash
how to create a detached container?
docker -d
docker run -d “IMAGE NAME/ID”
How to create a detached container
How to start a stopped container?
docker start “CONTAINER NAME/ID”