Skip to content

Instantly share code, notes, and snippets.

@jinnabaalu
Last active September 30, 2017 05:50
Show Gist options
  • Save jinnabaalu/570f2c85f617e26b8c62857c92d11ea0 to your computer and use it in GitHub Desktop.
Save jinnabaalu/570f2c85f617e26b8c62857c92d11ea0 to your computer and use it in GitHub Desktop.
Docker commands for volumes, docker containers, docker images, docker volumes, docker networks, docker swarm, docker swarm services, remove unused images, dangling

Docker Images

List Images

 docker images
 
 docker rmi <ImageNameOrImageId>

Tag Image

docker tag <IMAGE_NAME_OR_IMAGE_ID>:latest <IMAGE_NAME>:0.0.1

docker tag <IMAGE_NAME>:latest <IMAGE_NAME>:0.0.1

List Dangling Images

docker images -f dangling=true

Delete Unused Images

Remove Dangling Images

docker rmi $(docker images -f dangling=true -q)

Delete all the images

docker rmi $(docker images -q)

Docker compose

  docker-compose up -d      # By default it runs the docker-compose.yml file
  
  docker-compose -f docker-compose-sample up -d     # to run the containers with docker-compose-sample.yml file
  
  docker-compose -f docker-sample.yml -f dockersample2.yml up -d    # to run multiple docker files with one comand  

CONTAINERS

  docker ps     # to check the container status
  
  docker ps -a    # to check the docker container status even if the container exists
  
  docker logs <ContainerId>       # to check the logs of the container
  
  docker stop <Container_ID>      # to stop the docker container
  
  docker rm <Container_ID>      # to remobve the container, note to remember we can't remove the container when it is running, stop and remove
  
  docker container inspect <CONTAINER_ID> # Container inspection
  

TO REMOVE ALL CONTAINERS

  docker stop $(docker ps -a -q)
  
  docker rm $(docker ps -a -q)

Remove a container and its volume

docker rm -v <CONTAINER_NAME>

TO RESTART ALL DOCKER CONTAINER

  docker restart $(docker ps -a -q)

Stack

  docker stack ls

Service

List services

docker service ls

List services with filter

docker service ls -f "id=0bcjw"

docker service ls --filter mode=global

Service Logs

docker service logs --details <ServiceId>

docker service logs --follow <ServiceId>      #continue streaming

Format Services

docker service ls --format "{{.ID}}: {{.Mode}} {{.Replicas}}"

Inspect Services

docker service inspect <SERVICE_NAME>

docker service inspect --pretty <SERVICE_NAME>

Volume

List Volumes

docker volume ls # list all the volumes

Inspect Volume

  docker volume inspect <VOLUME_NAME> # details about the volume

List Dangling Volumes

docker volume ls -f dangling=true

Remove Volume

  docker volume rm <VOLUME_NAME>

Remove Dangling Volumes

docker volume rm $(docker volume ls -f dangling=true -q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment