Docker commands

Recap and cheat sheet

# List Docker CLI commands
docker
docker container --help

# Display Docker version and info
docker --version
docker version
docker info

# Execute Docker image
docker run hello-world

# List Docker images
docker image ls

# List all images on this machine
docker image ls -a

# Remove specified image from this machine
docker image rm <image id>            

# Remove all images from this machine
docker image rm $(docker image ls -a -q)   

# List Docker containers (running, all, all in quiet mode)
docker container ls (running)
docker container ls --all (all)
docker container ls -aq (all in quite mode)
docker container ls -a (all, even those not running)

# Create image using directory's Dockerfile
docker build -t friendlyhello .  

# Run "friendlyhello" mapping port 4000 to 80
docker run -p 4000:80 friendlyhello  

# Same thing, but in detached mode
docker run -d -p 4000:80 friendlyhello         

# Gracefully stop the specified container
docker container stop <hash>           

# Force shutdown of the specified container
docker container kill <hash>      

# Remove specified container from this machine
docker container rm <hash>

# Remove all containers
docker container rm $(docker container ls -a -q)         

# Log in this CLI session using your Docker credentials
docker login            

# Tag <image> for upload to registry
docker tag <image> username/repository:tag  

# Upload tagged image to registry
docker push username/repository:tag            

# Run image from a registry
docker run username/repository:tag

# Get all services associated with the 'getstartedlab' stack
docker stack services getstartedlab

# List stacks or apps
docker stack ls

# Run the specified Compose file
docker stack deploy -c <composefile> <appname>
docker stack deploy -c dockder-compose.yml getstartedlab #example

# List running services associated with an app
docker service ls

# List tasks associated with an app
docker service ps <service>
docker service ps getstartedlab_web #example

# Inspect task or container
docker inspect <task or container>

# List container IDs
docker container ls -q

# Tear down an application
docker stack rm <appname>

# Take down a single node swarm from the manager 
docker swarn leave --force


comments powered by Disqus