Docker Cheatsheet

By | 09/11/2019

Create and run a docker container with default command (optional)

$ docker run <container> <start up command>

Docker run is actually 2 command:

docker create + docker start

docker create – Creates container from image
docker start – starts container from id

See all containers running on your machine

$ docker ps

To see all containers ever run on your machine

$ docker ps --all

Watch output from docker terminal and display

$ docker start -a container id>

Purge all containers on system

$ docker system prune

Retrieve all information outputted from running container

$ docker logs <container id>

Stop running container

Send hardware signal to terminate the container on it’s own time (SIGTERM) command – preferred but will issue SIGKILL if not shut in 10 seconds

$ docker stop <container id>

If you want to kill the container right now without shutting down any running processes, send the SIGKILL signal

$ docker kill <container id>

Run redis server in docker

$ docker run redis

# in new terminal window use the execute (exec) & -it flags to run a command on that container.
-i is STDIN
-t is showing to terminal formatted

$ docker exec -it <container id> redis-cli
$ docker exec -it <container id> <command>

To start a shell in your running container (or sh / bash / zsh / powershell)

$ docker exec -it <container id> sh