Docker CLI cheat sheet
Basic Docker Commands
docker pull [OPTIONS] NAME[:TAG|@DIGEST] |
Downloads image -q less verbose $ docker pull jenkins/jenkins:lts-jdk11 |
docker run [OPTIONS] IMAGE [COMMAND] [ARG…] |
Creates a new container -d run a container in background and print container id $ docker run -d –name jenkins -p 8085:8080 -v “/docker_volume/jenkins”:/var/jenkins_home jenkins/jenkins:lts-jdk11 |
docker images [OPTIONS] [REPOSITORY[:TAG]] |
Lists all images, repositories, tags and their size -a show all images (default hides intermediate images) |
docker build [OPTIONS] PATH | URL | - |
Build an image from the docker file, by default it looks for ‘Dockerfile’ $ docker build . |
docker exec [OPTIONS] CONTAINER COMMAND [ARG…] |
Execute a command in a running container -i interactive mode, keeps STDIN open $ docker container exec -it mariadb /bin/bash |
Cleanup
docker rmi [OPTIONS] IMAGE [IMAGE…] |
Remove one or more images -f force remove image $ docker rmi -f 8b7c2b10838b 1a7a055a6252 |
docker rm [OPTIONS] CONTAINER [CONTAINER…] |
Remove one or more containers -f force remove running container |
Container
docker container start [OPTIONS] CONTAINER [CONTAINER…] |
Start one or more containers -i interactive mode; attach container’s STDIN $ docker container start jenkins |
docker container stop [OPTIONS] CONTAINER [CONTAINER…] |
Stop one or more containers $ docker container stop jenkins |
docker container ls [OPTIONS] |
List containers -a show all containers (default shows just running) $ docker container ls |
docker container logs [OPTIONS] CONTAINER |
Display logs of the container -f follow log output $ docker container logs –tail 5 jenkins |
docker container exec [OPTIONS] CONTAINER COMMAND [ARG…] |
Run a command in a running container -d run command in the background $ docker container exec -it jenkins /bin/bash |
docker container diff CONTAINER |
List changed files and directories on the container $ docker container diff jenkins |
docker container stats [OPTIONS] [CONTAINER…] |
Display live stream on container resource usage statistics $ docker container stats jenkins |
docker container inspect [OPTIONS] CONTAINER [CONTAINER…] |
Display detailed information on one or more container’s $ docker container inspect jenkins |
docker container kill [OPTIONS] CONTAINER [CONTAINER…] |
Kill one or more running container’s $ docker container kill jenkins |