Skip to content

Instantly share code, notes, and snippets.

@imtiazShakil
Last active May 28, 2025 06:35
Show Gist options
  • Save imtiazShakil/017a86de6525704e56e3949a43cf8812 to your computer and use it in GitHub Desktop.
Save imtiazShakil/017a86de6525704e56e3949a43cf8812 to your computer and use it in GitHub Desktop.
Docker Commands

Docker Basics

# get id of active containers
docker ps
docker ps -a # get all containers

docker stop <the-container-id>
docker rm <the-container-id>

# stop and remove
docker rm -f <the-container-id>

# create new tag from existing tag
docker tag myapp:latest myapp:v1.0.0

# remove tag
docker rmi myapp:v1.0.0

# remove specific imageId
docker rmi <imageId>

# remove all dangling images (with <none> tag)
docker image prune

# execute arbitary commands in a running container
docker exec <container-id> <command>
# run interactive commands in a running container
docker exec -it <container-id> bash

# list all images
docker image ls
docker images

# get history of a docker image
docker history --no-trunc <image-id> > image-id-history.txt

# run interactive bash on an image id
docker run -it --entrypoint=/bin/bash <name-of-image/image-id>

# Removes all stopped containers.
docker container prune

# remove all stopped containers, unused networks, dangling images, dangling build-cache
docker system prune
# add all volumes not used, all images with no container associated, all build cache
docker system prune -a --volumes

# list all local volumes
docker volume ls
# inspect a specific volume, to get the exact physical location
docker volume inspect volume_name
# docker copy file to volume (that has attached container)
docker cp SRC container_name:DEST

# docker disk upsage
docker system df # add -v option for more details

Debug Java Apps

docker run -e "JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n" -p 8080:8080 -p 5005:5005 -t mycontainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment