Docker Quick Cheat Sheet

Docker Quick Cheat Sheet

Override the CMD in Docker

docker run -ti --entrypoint='/bin/sh' [docker-image-name]

Delete Old Images

docker rmi [docker-image-id]

Force Deletion of Images

docker rmi [docker-image-id] --force

How to Pull/Update All Local Images

docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull

Start and Connect to a Docker Container

docker run -i -t [my-docker-image]:[tag] /bin/bash

Start in Detached Mode

docker run -d [my-docker-image]

Stop the Docker Container

docker stop [my-container-id]

Delete all Exited Containers

You can see all exited containers using “docker ps -a”

docker rm -v $(docker ps -a -q -f status=exited)

How to Shell Into a Running Docker Container By Name or By Container ID

(You can get away with typing the first few unique characters of the container_id)

# By container ID
docker exec -it [my-container-id] /bin/bash
# By container name
docker exec -it [my-container-name] /bin/bash

Setting Environment Parameters Inside a Docker Container During Startup.

docker -e [environment_variables]

Start a Specific Container

docker run --name [my-container-name] -d [my-docker-image]

 

Leave a Reply