Docker is a popular platform for containerization, and it comes with a variety of commands to manage containers, images, networks, and volumes. Here’s a list of some commonly used Docker commands, with examples:
Container Management:
Docker run:
-Creates and starts a container from an image.
$ docker run -d — name my_container nginxDocker ps:
-Lists running containers.
$ docker psdocker ps -a:
-Lists all containers (running and stopped).
$ docker ps -aDocker stop:
-Stops a running container.
$ docker stop my_containerDocker start:
-Starts a stopped container.
$ docker start my_containerDocker restart:
-Restarts a container.
$ docker restart my_containerDocker exec:
— Executes a command in a running container.
$ docker exec -it my_container bashDocker rm:
— Removes one or more containers.
$ docker rm my_container
Image Management:
Docker images:
— Lists all available images.
$ docker imagesDocker pull:
— Pulls an image from a registry.
$ docker pull ubuntu:latestDocker rmi:
— Removes one or more images.
$ docker rmi ubuntu:latestDocker build:
— Builds a Docker image from a Dockerfile.
$ docker build -t custom_image:tag .
Network Management:
docker network ls:
— Lists all networks.
$ docker network lsdocker network create:
— Creates a new network.
$ docker network create my_networkdocker network connect:
— Connects a container to a network.
$ docker network connect my_network my_container
Volume Management:
docker volume ls:
— Lists all volumes.
$ docker volume lsDocker volume create:
— Creates a new volume.
$ docker volume create my_volumeDocker volume inspect:
— Displays detailed information about a volume.
$ docker volume inspect my_volume
These are just a few examples, and there are many more Docker commands available. You can explore the Docker documentation for more in-depth information: [Docker CLI documentation]. For additional information on coding and programming, you may also visit.
Top comments (0)