Docker notes
| 2 minute read | Using 271 words
Here are some of the most useful Docker commands that you might find handy
-
docker run [OPTIONS] IMAGE [COMMAND] [ARG…]
- Starts a new container from a specified image.
- Example:
docker run -d -p 80:80 nginx
(Starts an Nginx container and maps port 80).
-
docker ps [OPTIONS]
- Lists running containers. Use
-a
to show all containers (default shows just running). - Example:
docker ps -a
(Shows all containers).
- Lists running containers. Use
-
docker stop [OPTIONS] CONTAINER [CONTAINER…]
- Stops one or more running containers.
- Example:
docker stop my_container
(Stops the container named ‘my_container’).
-
docker rm [OPTIONS] CONTAINER [CONTAINER…]
- Removes one or more containers.
- Example:
docker rm my_container
(Removes the container named ‘my_container’).
-
docker images [OPTIONS] [REPOSITORY[:TAG]]
- Lists images.
- Example:
docker images
(Shows all available images).
-
docker rmi [OPTIONS] IMAGE [IMAGE…]
- Removes one or more images.
- Example:
docker rmi nginx
(Removes the Nginx image).
-
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
- Pulls an image or a repository from a registry.
- Example:
docker pull ubuntu
(Pulls the latest Ubuntu image).
-
docker build [OPTIONS] PATH | URL | -
- Builds an image from a Dockerfile.
- Example:
docker build -t my_image .
(Builds an image named ‘my_image’ from the Dockerfile in the current directory).
-
docker exec [OPTIONS] CONTAINER COMMAND [ARG…]
- Runs a command in a running container.
- Example:
docker exec -it my_container bash
(Runs a bash shell in ‘my_container’).
-
docker logs [OPTIONS] CONTAINER
- Fetches the logs of a container.
- Example:
docker logs my_container
(Displays logs of ‘my_container’).
-
docker volume create [OPTIONS] [VOLUME]
- Creates a new volume.
- Example:
docker volume create my_volume
(Creates a volume named ‘my_volume’).
-
docker network create [OPTIONS] NETWORK
- Creates a new network.
- Example:
docker network create my_network
(Creates a network named ‘my_network’).
Page link: /posts/docker-commands/