Navigate back to the homepage

Docker Cheat Sheet

Rommel Porras
August 10th, 2019 · 1 min read

A concise cheat sheet for everyday Docker commands.

Installation

  • Ubuntu Docker installation
  • Docker for Mac
  • Docker Desktop for Windows

Docker Lifecycle

CommandsDescriptions
docker createcreates a container but does not start it.
docker imagesList all images that are locally stored with the Docker Engine
docker runcreates and starts a container in one operation.
docker rmdeletes a container.
docker updateupdates a container’s resource limits.

Docker Ship Commands

CommandsDescriptions
docker loginLog in to a Docker Hub registry.
docker pull **rommelporras/laravel-php:7.3**Pull an image from a registry.
docker tag laravel-php:7.3 **rommelporras/laravel-php:7.3**Retag a local image with a new image name and tag.
docker push **yourrepository/laravel-php:7.3**Push an image to a registry

Docker Build Commands

CommandsDescriptions
docker build -t **laravel-php:7.3**Build an image from the Dockerfile in the current directory and tag the image
docker imagesList all images that are locally stored with the Docker engine
docker rmi **laravel-php:7.3**Delete an image from the local image store

Docker Run Commands

CommandsDescriptions
docker run -d -p 3000:80 laravel-php:7.3“-d” To run the container in the background process. “-p 3000:80” expose port 3000 externally and map to port 80. “laravel-php:7.3” container name
docker stop **laravel-php:7.3**Stop a running container through SIGTERM
docker kill **laravel-php:7.3**Stop a running container through SIGKILL
docker rm -f $(docker ps -aq)Delete all running and stopped containers
docker psList the running containers
docker ps –aTo see all the running and stopped containers
docker exec -it **web** **bash**Create a new bash process inside the container and connectit to the terminal
docker logs --tail 100 webPrint the last 100 lines of a container’s logs
docker eventsGet Events

Docker Repository and Registry Commands

CommandsDescriptions
docker loginlogin to a registry.
docker logoutlogout from a registry.
docker searchsearches registry for image.
docker pullpulls an image from registry to local machine.
docker pushpushes an image to the registry from local machine.

Docker Commands Basic Structure:

  • Image — A snapshot file of a container. Create containers by pulling and running Docker Images.
  • Docker Hub / Registry* — A public cloud-based registry service for developers to share their code on.
  • [options] — Add options to your Docker commands to change the results. Each command has multiple options available.
  • [command] — Enter the parameters for the Docker command, this could be a filename or container ID.
  • [arg] — Set additional argument variables.
  • [env] — Use to configure environment variables.
  • [init] — Initialize a swarm (by default, Docker will designate chosen machine as manager node).
  • [ca] — Show root Certificate Authority (auto-generated by init command).
  • [join] — Join a swarm as a worker/manager node.
  • [join-token] — Manage join tokens—define worker or manager accordingly.
  • [leave] — When implemented on a worker, the command prompts the node to leave the swarm.
  • [–force] — When implemented on a manager, the command forces the node to leave the swarm.
  • [tag] — The tag parameter is often part of the image name, but as your swarm develops you can adjust the tag without changing the base image name.
  • [unlock] — Unlock swarm manager with a user-own unlock key.
  • [unlock-key] — Manage the unlock key, useful to unlock a manager node.
  • [update] — Update the swarm.

Starting & Stopping Containers

Starting: docker start nginx

Stopping: docker stop nginx

Restarting: docker restart nginx

Pausing: docker pause nginx

Unpausing: docker unpause nginx

Blocking a Container: docker wait nginx

Sending a SIGKILL: docker kill nginx

Connecting to an Existing Container: docker attach nginx


Getting Information about Containers

Running Containers: docker ps / docker ps -a

Container Logs: docker logs infinite

Inspecting Containers: docker inspect infinite / docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)

Containers Events: docker events infinite

Public Ports: docker port infinite

Running Processes: docker top infinite

Container Resource Usage: docker stats infinite

Inspecting changes to files or directories on a container’s filesystem: docker diff infinite

Join our email list and get notified about new content

Be the first to receive our latest content with the ability to opt-out at anytime. We promise to not spam your inbox or share your email with any third parties.

More articles from DevOps Cycle

Setup Ghost Blog on AWS EC2 and RDS

A full guide for installing, configuring and running Ghost on your AWS EC2 Ubuntu 18.04 server, for use in production. Setup a Ghost blog/project on AWS.

August 2nd, 2019 · 6 min read

DevOps Importance and Benefits?

DevOps—the amalgamation of development (Dev) and operations (Ops) teams—is an organizational approach that enables faster development of applications and easier maintenance of existing deployments.

December 1st, 2019 · 6 min read
© 2019 DevOps Cycle
Link to $https://twitter.com/devopscycleLink to $https://facebook.com/devopscycleLink to $https://github.com/rommelporrasLink to $https://m.do.co/c/1ba0ac3af2f6