22 Docker Commands You Must Know As a Beginner
What is Docker?
Docker is a lightweight virtualized environment called a container that is used for the development, deployment, and management of applications. It is mostly used as a platform for software development to create distributed applications that operate effectively in many environments.
Compared to VMs(Virtual Machines), Docker comes in handy with a lots of features and commands. To get started, you first have to get Docker installed directly on your Machines(Mac, Windows, Linux).
In this article, I have compiled the top 25 commands which I think every beginner Docker users must know. Remember to give me a clap 👏 if you find this helpful. Without wasting too much of our time, let’s get started.
1. To show all images in your Docker
$ docker images
2. To show all running containers
$ docker ps
3. To show all available running containers
$ docker ps -a
4. To delete an image (Note: The particular image must not have a container in use)
$ docker image rm <image_name>
5. To delete image even if it has a container in use
$ docker image rm <image_name> -f
6. To delete a container
$ docker container rm <container_name>
7. To remove all images, containers and volumes
$ docker system prune -a
8. To build image
$ docker build -t <name_of_image>
9. To build image with tag
$ docker build -t <name_of_image>:v1 .
10. To start a container
$ docker start <container_name>
11. To start an image with a specified port
$ docker run -name <container_name> -p 4000:4000 <image_name>
12. To stop a container
$ docker stop <container_name>
13. Deploying react.js application on docker
$ docker run -name <container_name> -p 4000:4000 -rm -v <app.js_path> -v <node_modules_path>:ro <image_name>
14. To start up a docker-compose.yaml file
$ docker-compose up
15. To shutdown container and delete it
$ docker-compose down
16. To delete container and images
$ docker-compose down -rmi all
17. To delete container, images and volumes
$ docker-compose down -rmi all -v
18. To clone imagename from hub
$ docker build -t <username>/<hub_name>
19. To login remotely from terminal
$ docker login
20. To push to dockerhub
$ docker push <image_name>
21. To pull latest nginx
$ docker pull nginx:latest
22. To run nginx container
$ docker run -p 8000:80 nginx
If you’ve enjoyed this article, don’t forget to give me a clap and follow me on my social media handles