Cheat Sheet: Docker CLI
»Docker«
Docker, Cheat Sheet, CLI, Terminal, Command line interface
I’m new to Docker. So this cheatsheet is primarily for me to help to remember commands for handling containers as well as images.
See Docker command line reference for the whole reference.
Containers
Listing containers
# List running containers
docker ps
# List all containers
docker ps -a
Starting/Stopping containers
# Start
docker start containerName
# Stop
docker stop containerName
Removing containers
# Remove container
docker rm containerName
# Stop and remove container
docker rm -f containerName
# Remove all exited containers
docker rm -v $(docker ps -a -q -f status=exited)
Running commands in new containers
docker run imageName command arguments
# Example
docker run docker/whalesay cowsay Hello
# Assign a name to the container
docker run --name myName docker/whalesay cowsay Hello
# Run with a specific tag of an image
docker run node:6.9.1 node --version
# Run container in background
docker run -d -p 80:80 --name webserver nginx
See Docker run reference for more …
Images
Listing local images
docker images
Removing images
docker rmi imageName
# Remove unwanted dangling images
docker rmi $(docker images -f "dangling=true" -q)
Searching for images
# Search the Docker Hub for images
docker search searchWord
Pulling images
docker pull imageName
# Pull a specific tag
docker pull imageName:tag
# Example: Get a specific node version
docker pull node:6.9.1
Building image from Dockerfile
docker build .
# Name the image
docker build -t imageName .
# Tag the image
docker build -t imageName:1.0.0 .
See Dockerfile reference in addition.
Related posts
- How to flash ESP8266 (and ESP32) to use Espruino firmware on macOS
- Helpers and tips for npm run scripts
- JSConf Budapest 2017 – A personal recap
Comments
Comments are removed for now. Feel free to contact me via Twitter in case you’d like to talk about this blog post: @mkuehnel.