DEV Community

Shubham Yadav
Shubham Yadav

Posted on • Updated on

Docker Commands 🐳

docker images commands

  • Shows the help for the docker images command.
docker images --help 
Enter fullscreen mode Exit fullscreen mode
  • pulls an image from a registry.
 docker pull [image] `
Enter fullscreen mode Exit fullscreen mode
  • Pulls an image from a registry and tag it.
 docker pull [image]:[tag] 
Enter fullscreen mode Exit fullscreen mode
  • Lists all images in the local registry.
 docker images 
Enter fullscreen mode Exit fullscreen mode
  • list image id only
 docker images -q 
Enter fullscreen mode Exit fullscreen mode
  • list dangling images
 docker images -f "dangling=true" 
Enter fullscreen mode Exit fullscreen mode
  • Runs an image in a new container.
 docker run [image] 
Enter fullscreen mode Exit fullscreen mode
  • Lists all running containers.

docker ps

  • Runs an image in a new container and names it.
 docker run --name [container] [image] 
Enter fullscreen mode Exit fullscreen mode
  • Runs an image in a new interactive container.
 docker run -it [image] 
Enter fullscreen mode Exit fullscreen mode
  • Runs an image in a new interactive container and names it.
 docker run -it --name [container] [image] 
Enter fullscreen mode Exit fullscreen mode
  • Inspects a container.
 docker inspect [container] 
Enter fullscreen mode Exit fullscreen mode
  • Removes an image from the local registry.
 docker rmi [image] 
Enter fullscreen mode Exit fullscreen mode
  • Removes an image from the local registry and force remove it.
 docker rmi -f [image] 
Enter fullscreen mode Exit fullscreen mode
  • Shows the history of an image.
 docker history [image] 
Enter fullscreen mode Exit fullscreen mode

docker container commands

  • Lists all running containers.
 docker ps 
Enter fullscreen mode Exit fullscreen mode
  • Runs an image in a new container.
 docker run [image] 
Enter fullscreen mode Exit fullscreen mode
  • Starts a container.
 docker start [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Stops a container.
 docker stop [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Pauses a container.
 docker pause [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Unpauses a container.
 docker unpause [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Restarts a container.
 docker restart [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Shows the running processes of a container.
 docker top [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Shows the resource usage of a container.
 docker stats [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Inspects a container.
 docker inspect [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Attaches to a container.
 docker attach [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode

docker attach usage : Use docker attach to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.

  • Kills a container.
 docker kill [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Removes a container.
 docker rm [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode
  • Shows the history of a container.
 docker history [container-name] / [container-id] 
Enter fullscreen mode Exit fullscreen mode

dockerfile commands

  • Builds an image from a Dockerfile.
 docker build [path] 
Enter fullscreen mode Exit fullscreen mode
  • Builds an image from a Dockerfile and tag it.
 docker build -t [image] [path] 
Enter fullscreen mode Exit fullscreen mode

docker compose commands

  • Shows the configuration of a service.
 docker compose config [service] 
Enter fullscreen mode Exit fullscreen mode
  • Starts services.
 docker-compose up [service] 
Enter fullscreen mode Exit fullscreen mode
  • Starts services and keep them running.
 docker-compose up -d [service] 
Enter fullscreen mode Exit fullscreen mode
  • Stops services.
 docker-compose down [service] 
Enter fullscreen mode Exit fullscreen mode
  • Lists all running services.
 docke compose ps 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)