What are the common Docker commands for managing containers?

0136

Common Docker Commands for Managing Containers

Docker is a powerful tool for containerizing applications, making it easier to build, deploy, and manage them. As a Docker expert and mentor, I'll guide you through the common Docker commands for managing containers.

Docker Container Lifecycle Commands

  1. docker run: This command is used to create and start a new container from a specified Docker image. For example, to run a Nginx web server container, you can use the following command:
docker run -d -p 80:80 --name my-nginx nginx:latest

This command will pull the latest Nginx image from the Docker Hub, create a new container, and start it in detached mode (-d) while mapping port 80 on the host to port 80 in the container.

  1. docker start: This command is used to start an existing, stopped container. For example, to start the my-nginx container:
docker start my-nginx
  1. docker stop: This command is used to stop a running container. For example, to stop the my-nginx container:
docker stop my-nginx
  1. docker restart: This command is used to restart a container. For example, to restart the my-nginx container:
docker restart my-nginx
  1. docker rm: This command is used to remove a container. For example, to remove the my-nginx container:
docker rm my-nginx
  1. docker pause and docker unpause: These commands are used to pause and unpause a running container, respectively. For example, to pause the my-nginx container:
docker pause my-nginx

And to unpause it:

docker unpause my-nginx

Docker Container Management Commands

  1. docker ps: This command is used to list all running containers. To list all containers, including stopped ones, you can use the -a flag:
docker ps -a
  1. docker inspect: This command is used to inspect a container and retrieve detailed information about it. For example, to inspect the my-nginx container:
docker inspect my-nginx
  1. docker logs: This command is used to view the logs of a container. For example, to view the logs of the my-nginx container:
docker logs my-nginx
  1. docker exec: This command is used to execute a command inside a running container. For example, to open a shell inside the my-nginx container:
docker exec -it my-nginx /bin/bash
  1. docker stats: This command is used to view real-time performance statistics for one or more containers. For example, to view the stats for all running containers:
docker stats
  1. docker top: This command is used to display the running processes of a container. For example, to view the running processes of the my-nginx container:
docker top my-nginx

These are the most common Docker commands for managing containers. As a Docker expert, I hope this overview helps you understand the core concepts and commands for managing your containers effectively. Let me know if you have any further questions!

0 Comments

no data
Be the first to share your comment!