Though the above pic is self explanatory, we’ll just discuss the basics / CLI commands for working with docker containers.
Create a container to run it later on with required image.
docker create --name <container-name> <image-name>
Run docker container
Run the docker container with the required image and specified command / process. ‘-d’ flag is used for running the container in background.
docker run -it -d --name <container-name> <image-name> bash
Used to pause the processes running inside the container.
docker pause <container-id/name>
Used to unpause the processes inside the container.
docker unpause <container-id/name>
Start the container, if present in stopped state.
docker start <container-id/name>
To stop the container and processes running inside the container:
docker stop <container-id/name>
To stop all the running docker containers
docker stop $(docker ps -a -q)
It is used to restart the container as well as processes running inside the container.
docker restart <container-id/name>
We can kill the running container.
docker kill <container-id/name>
Its preferred to destroy container, only if present in stopped state instead of forcefully destroying the running container.
docker rm <container-id/name>
To remove all the stopped docker containers
docker rm $(docker ps -q -f status=exited)
Source: ~ Docker CLI
Disclaimer: Content and image source has been mentioned. Special credits to concerned folks.