Docker Flashcards
How to see list of running containers in Docker?
docker container ls
docker container ls -a —– (show all containers)
how to remove container in Docker?
docker container rm [container id]
container id can be only first 3 digits
Create an run a container in foreground [Docker]
$ docker container run -it -p 80:80 nginx
Create an run a container in background
$ docker container run -d -p 80:80 nginx
difference between running container in foreground and background docker
You can start a docker container in detached mode with a -d option. So the container starts up and run in background. That means, you start up the container and could use the console after startup for other commands.
The opposite of detached mode is foreground mode. That is the default mode, when -d option is not used. In this mode, the console you are using to execute docker run will be attached to standard input, output and error. That means your console is attached to the container’s process.
In detached mode, you can follow the standard output of your docker container with docker logs -f .
List running containers [Docker]
$ docker container ls
$ docker ps
List all containers (Even if not running) [Docker]
$ docker container ls -a
Stop container
Stop all running containers
[Docker]
$ docker container stop [ID]
$ docker stop $(docker ps -aq)
Remove container (Can not remove running containers, must stop first) To remove a running container use force(-f)
$ docker container rm [ID]
$ docker container rm [ID] [ID] [ID]
Get logs (Use name or ID) [Docker]
$ docker container logs [NAME]
List processes running in container [Docker]
$ docker container top [NAME]
Docker containers are often compared to virtual machines but they are actually just processes running on your host os. In Windows/Mac, Docker runs in a mini-VM so to see the processes youll need to connect directly to that. On Linux however you can run “ps aux” and see the processes directly
Remove all images [Docker]
$ docker rmi $(docker images -a -q)
About images [Docker]
- Images are app bianaries and dependencies with meta data about the image data and how to run the image
- Images are no a complete OS. No kernel, kernel modules (drivers)
- Host provides the kernel, big difference between VM
View info on container [Docker]
$ docker container inspect [NAME]