DEV Community

Cover image for Essential Docker Commands Every Software Engineer Should Know
Odumosu Matthew
Odumosu Matthew

Posted on

Essential Docker Commands Every Software Engineer Should Know

Introduction:

Docker has revolutionized the way developers build, ship, and run applications by providing a lightweight and consistent environment for software development. Whether you are deploying a small web application or managing a complex microservices architecture, Docker simplifies the process and enhances efficiency. Understanding and mastering Docker commands is crucial for any software engineer who aims to leverage the full potential of containerization. This article compiles 50 essential Docker commands, providing a clear and concise reference guide to help you manage containers, images, networks, and more effectively. Dive in to boost your Docker proficiency and streamline your development workflow.

1. docker build -t .
Purpose: Build a Docker image from a Dockerfile in the current directory and tag it.

Example: docker build -t myapp .

2. docker pull
Purpose: Download a Docker image from a registry (e.g., Docker Hub).

Example: docker pull nginx

3. docker images
Purpose: List all Docker images on the local machine.

Example: docker images

4. docker rmi
Purpose: Remove a Docker image from the local machine.

Example: docker rmi nginx

*5. docker tag *
Purpose: Add a new tag to an image.

Example: docker tag myapp:latest myapp:v1

6. docker run -d --name
Purpose: Run a Docker container in detached mode.

Example: docker run -d --name mycontainer nginx

7. docker run -it --name /bin/bash
Purpose: Run a Docker container in interactive mode with a bash shell.

Example: docker run -it --name mycontainer ubuntu /bin/bash

8. docker ps
Purpose: List all running Docker containers.

Example: docker ps

9. docker ps -a
Purpose: List all Docker containers, including stopped ones.

Example: docker ps -a

10. docker stop
Purpose: Stop a running Docker container.

Example: docker stop 123456

11. docker start
Purpose: Start a stopped Docker container.

Example: docker start 123456

12. docker restart
Purpose: Restart a Docker container.

Example: docker restart 123456

13. docker rm
Purpose: Remove a Docker container.

Example: docker rm 123456

14. docker exec -it /bin/bash
Purpose: Execute a command in a running Docker container.

Example: docker exec -it 123456 /bin/bash

15. docker volume create
Purpose: Create a new Docker volume.

Example: docker volume create myvolume

16. docker volume ls
Purpose: List all Docker volumes.

Example: docker volume ls

17. docker volume rm
Purpose: Remove a Docker volume.

Example: docker volume rm myvolume

18. docker network create
Purpose: Create a new Docker network.

Example: docker network create mynetwork

19. docker network ls
Purpose: List all Docker networks.

Example: docker network ls

20. docker network rm
Purpose: Remove a Docker network.

Example: docker network rm mynetwork

21. docker run --name --network
Purpose: Run a Docker container and attach it to a specified network.

Example: docker run --name mycontainer --network mynetwork nginx

22. docker-compose up
Purpose: Start and run the containers defined in a docker-compose.yml file.

Example: docker-compose up

23. docker-compose down
Purpose: Stop and remove the containers defined in a docker-compose.yml file.

Example: docker-compose down

24. docker-compose build
Purpose: Build or rebuild services defined in a docker-compose.yml file.

Example: docker-compose build

25. docker-compose ps
Purpose: List the status of services defined in a docker-compose.yml file.

Example: docker-compose ps

26. docker-compose logs
Purpose: View output from containers defined in a docker-compose.yml file.

Example: docker-compose logs

27. docker-compose exec
Purpose: Execute a command in a running container defined in a docker-compose.yml file.

Example: docker-compose exec web /bin/bash

28. docker-compose stop
Purpose: Stop services defined in a docker-compose.yml file.

Example: docker-compose stop

29. docker-compose restart
Purpose: Restart services defined in a docker-compose.yml file.

Example: docker-compose restart

30. docker swarm init
Purpose: Initialize a Docker Swarm.

Example: docker swarm init

31. docker swarm join
Purpose: Join a Docker Swarm as a worker or manager node.

Example: docker swarm join --token <token> <manager_ip>:<port>

32. docker node ls
Purpose: List all nodes in the Swarm.

Example: docker node ls

33. docker service create --name
Purpose: Create a new service in the Swarm.

Example: docker service create --name web nginx

34. docker service ls
Purpose: List all services in the Swarm.

Example: docker service ls

35. docker service scale =
Purpose: Scale a service to the specified number of replicas.

Example: docker service scale web=5

36. docker service rm
Purpose: Remove a service from the Swarm.

Example: docker service rm web

37. docker login
Purpose: Log in to a Docker registry.

Example: docker login

38. docker logout
Purpose: Log out from a Docker registry.

Example: docker logout

39. docker push
Purpose: Push a Docker image to a registry.

Example: docker push myapp:latest

40. docker pull
Purpose: Pull a Docker image from a registry.

Example: docker pull myapp:latest

41. docker tag //:
Purpose: Tag an image for a specific registry and repository.

Example: docker tag myapp:latest myregistry/myapp:v1

42. docker search
Purpose: Search Docker Hub for images.

Example: docker search nginx

43. docker system df
Purpose: Show Docker disk usage.

Example: docker system df

44. docker system prune
Purpose: Remove unused data (containers, networks, images, and volumes).

Example: docker system prune

45. docker system info
Purpose: Display system-wide information.

Example: docker system info

46. docker stats

Purpose: Display a live stream of container(s) resource usage statistics.

Example: docker stats

47. docker inspect
Purpose: Return low-level information on Docker objects.

Example: docker inspect mycontainer

48. docker events
Purpose: Get real-time events from the Docker server.

Example: docker events

49. docker top
Purpose: Display the running processes of a container.

Example: docker top mycontainer

50. docker update --
Purpose: Update the configuration of one or more containers.

Example: docker update mycontainer --restart=always

These commands provide a comprehensive overview of Docker functionalities essential for software engineers.

LinkedIn Account : LinkedIn
Twitter Account: Twitter
Credit: Graphics sourced from analyticsvidhya

Top comments (0)