Hello world,
I have been learning Docker 🐳. I wanted to share some basics command to get started as a developer, I hope you know the basics about What is docker, containers or virtualization?
I am using Windows 10 2004 Update 🐱👓, this update comes with WSL2. In this tutorial, I am using Ubuntu on WSL2.
Information ℹ
Show all commands
$ docker
Docker version
$ docker version
Show information like number of containers
$ docker info
Containers ⛴
Create and run a container in foreground
docker container run -it -p 80:80 nginx
Create and run a container in background
$ docker container run -d -p 80:80 nginx
Running container
Naming containers
$ docker container run -d -p 80:80 --name nginx-proxy nginx
List running containers
$ docker container ls
List all containers
$ docker container ls -a
Stop container
$ docker container stop [ID]
Stop all containers
$ docker stop $(docker ps -aq)
Remove container (Can't remove running container)
$ docker container rm [ID]
Remove running container
$ docker container rm -f [ID]
Remove multiple containers
$ docker container rm [ID] [ID] [ID]
Remove all containers
$ docker rm $(docker ps -aq)
Images 📸
List the all images we have downloaded
$ docker images
Pull new image from docker hub
$ docker pull [IMAGE_NAME]
Remove image or images
$ docker image rm [IMAGE]
$ docker rmi $(docker images -a -q)
Note: Any suggestion?
Top comments (4)
I regularly use
docker system prune
, but not really sure what it doesn't entail.It removes unused Containers, dangling Images and unused Networks.
Dangling Image is what it's called if you stop a docker pull midway. The Image is not finished loading and classified as "dangling". There are also those that you build and don't give a Name to. Those old images are the ones that are untagged and display as "none" on their name when you run 'docker images'.
There are two equivalent commands for Images and volumes too, docker image prune or docker volume prune, if you want to clean those up too by "unused" Status :)
Nice article. I am really addicted to Docker. I'll make a contribution:
$docker exec -it IMAGEID bash
to enter in image.
Yes