Container States
- Running (Started)
- Exited (Stopped)
- Paused
Docker Container Creation modes
- Attached mode:
- Our terminal will recieve outputs from containter stdout, stderr
docker container run jenkins # press ctrl+c to exit the container and also the container outputs to your terminal - Detached Mode (background)
- Container runs in the background an you will recieve container id
docker container run -d jenkins - Interactive Terminal
- Create a container and login into interactive shell
docker container run -it jenkins /bin/bash docker container run -it alpine /bin/sh
Listing Containers
docker container lsordocker pswill show all the containers in running statedocker container ls -aordocker ps -awill show all the containers in running and stopped state
Removing Containers
- Containers can be removed from stopped state, if they are in running state you have to force the delete
- To remove containers we need name/id
docker container rm <name-or-id>
docker container rm <name-or-id-container1> <name-or-id-container2> ..
- To remove all the containers
docker container rm -f $(docker container ls -a -q)
Docker CLI
- Cheatsheet
- use –help
docker container run --help
- Use Docker Documentation from here
