DEV Community

Cover image for πŸ‘©πŸΌβ€πŸ’» Docker for Beginners - By Beginner πŸ‘¨πŸΌβ€πŸ’»
Prathamesh More
Prathamesh More

Posted on

29 9

πŸ‘©πŸΌβ€πŸ’» 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/

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay