Docker notes

   |   2 minute read   |   Using 271 words

Here are some of the most useful Docker commands that you might find handy

  1. 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).
  2. docker ps [OPTIONS]

    • Lists running containers. Use -a to show all containers (default shows just running).
    • Example: docker ps -a (Shows all containers).
  3. docker stop [OPTIONS] CONTAINER [CONTAINER…]

    • Stops one or more running containers.
    • Example: docker stop my_container (Stops the container named ‘my_container’).
  4. docker rm [OPTIONS] CONTAINER [CONTAINER…]

    • Removes one or more containers.
    • Example: docker rm my_container (Removes the container named ‘my_container’).
  5. docker images [OPTIONS] [REPOSITORY[:TAG]]

    • Lists images.
    • Example: docker images (Shows all available images).
  6. docker rmi [OPTIONS] IMAGE [IMAGE…]

    • Removes one or more images.
    • Example: docker rmi nginx (Removes the Nginx image).
  7. docker pull [OPTIONS] NAME[:TAG|@DIGEST]

    • Pulls an image or a repository from a registry.
    • Example: docker pull ubuntu (Pulls the latest Ubuntu image).
  8. 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).
  9. 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’).
  10. docker logs [OPTIONS] CONTAINER

    • Fetches the logs of a container.
    • Example: docker logs my_container (Displays logs of ‘my_container’).
  11. docker volume create [OPTIONS] [VOLUME]

    • Creates a new volume.
    • Example: docker volume create my_volume (Creates a volume named ‘my_volume’).
  12. docker network create [OPTIONS] NETWORK

    • Creates a new network.
    • Example: docker network create my_network (Creates a network named ‘my_network’).


denis256 at denis256.dev