DEV Community

Cover image for 👩🏼‍💻 Docker for Beginners - By Beginner 👨🏼‍💻
Prathamesh More
Prathamesh More

Posted on

👩🏼‍💻 Docker for Beginners - By Beginner 👨🏼‍💻

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
Enter fullscreen mode Exit fullscreen mode

Docker

Docker version

$ docker version
Enter fullscreen mode Exit fullscreen mode

Show information like number of containers

$ docker info
Enter fullscreen mode Exit fullscreen mode

Containers ⛴

Create and run a container in foreground

docker container run -it -p 80:80 nginx
Enter fullscreen mode Exit fullscreen mode

Run a container in foreground

Create and run a container in background

$ docker container run -d -p 80:80 nginx
Enter fullscreen mode Exit fullscreen mode

Run in background

Running container

Running

Naming containers

$ docker container run -d -p 80:80 --name nginx-proxy nginx
Enter fullscreen mode Exit fullscreen mode

List running containers

$ docker container ls
Enter fullscreen mode Exit fullscreen mode

Running all containers

List all containers

$ docker container ls -a
Enter fullscreen mode Exit fullscreen mode

Stop container

$ docker container stop [ID]
Enter fullscreen mode Exit fullscreen mode

Stop container

Stop all containers

$ docker stop $(docker ps -aq)
Enter fullscreen mode Exit fullscreen mode

Remove container (Can't remove running container)

$ docker container rm [ID]
Enter fullscreen mode Exit fullscreen mode

Remove running container

$ docker container rm -f [ID]
Enter fullscreen mode Exit fullscreen mode

Remove multiple containers

$ docker container rm [ID] [ID] [ID]
Enter fullscreen mode Exit fullscreen mode

Remove all containers

$ docker rm $(docker ps -aq)
Enter fullscreen mode Exit fullscreen mode

Images 📸

List the all images we have downloaded

$ docker images
Enter fullscreen mode Exit fullscreen mode

All images

Pull new image from docker hub

$ docker pull [IMAGE_NAME]
Enter fullscreen mode Exit fullscreen mode

Pull new image

Remove image or images

$ docker image rm [IMAGE]
$ docker rmi $(docker images -a -q)
Enter fullscreen mode Exit fullscreen mode

Note: Any suggestion?

Happy coding

Looking for an entry-level job as Backend Developer or Full Stack Web Developer

http://pprathameshmore.github.io/

Top comments (4)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I regularly use docker system prune, but not really sure what it doesn't entail.

Collapse
 
habereder profile image
Raphael Habereder • Edited

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 :)

Collapse
 
abrandao profile image
Anderson Brandão

Nice article. I am really addicted to Docker. I'll make a contribution:

$docker exec -it IMAGEID bash

to enter in image.

Collapse
 
pprathameshmore profile image
Prathamesh More

Yes