7/6/2017 - 2:28 AM

Docker CheatSheet

Docker CheatSheet

Docker Container LifeCycle

Create Docker Conatiner

docker container create

Starts a Docker Container

docker container start

Creates and Starts a Container in Operation

docker container run -d -P -e AUTHOR="AayushTuladhar"
  • -d will create a container with the process detached from terminal
  • -P will publish all the exposed container ports to random ports on the Docker host
  • -e is how you pass environment variables to the container

Stops a running Container

docker container stop

Update Conatiner Resource Limit

docker container update

View All Running Containers

docker ps
docker ps -a

Docker Images LifeCycle

# Shows image currently in local repository
docker images

# Removes an Image from Local Registry
docker rmi <image>

# Pulls an Image from Registry
docker pull <image>

# Create Image from Dockerfile
docker build

# Delete all containers
docker rm $(docker ps -a -q)

# Delete all images
docker rmi $(docker images -q)

Pushing to Docker Registry

docker build . -t && docker push

Docker Maintenance

# Remove All Stopped Containers
docker ps -q |xargs docker rm 

# Removing All Unused Docker Images
docker images -q |xargs docker rmi

#Remove all exited containers
docker rm $(docker ps -a -f status=exited -q)

# Remove Docker Image (With Force)
docker rmi -f <imageName>

# Run a Container in Interactive Mode
docker container run -it alpine bin/sh