Docker has become an essential tool for every software developer. If you haven’t yet heard about Docker, it’s a free, powerful, and reliable tool for creating and deploying containers, available for Linux, macOS, and Windows. From the official Docker documentation:

“A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

“A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.”

Image for post

Docker architecture — docker.com

With Docker, developers can forget headaches when trying to deploy their apps. Your application is bundled as an image, and this image is deployed as a container in your server or on the cloud. With Docker Compose, you can even orchestrate the deployment of several services that together constitute an application.

Image for post

Photo by chuttersnap on Unsplash


Docker CLI commands

Docker offers a UI called Docker Dashboard, from where you can do some tasks, but the most usual way to work with Docker is through its CLI, so let’s see here some examples of the most useful and usual commands.

Create and run a container from an image

To create and run a container called “my_beautiful_container” with an official Ubuntu image, we would just use the [docker run](https://docs.docker.com/engine/reference/run/) command:

docker run -d — name my_beautiful_container ubuntu  ## run the container as a background process

docker run -it — name my_beautiful_container ubuntu /bin/bash  ## run the container and launch an interactive shell on it

When using the run command, we can also map a container port to a host machine port (very important for web servers) for instance:

docker run -p 1234:80 ubuntu  ## map the port 80 in the container to 1234 in the host machine

By their nature, containers don’t offer data persistence. If we need some data inside our container to be persisted after reboots, we have to use volumes, and that means mounting a host machine folder into the container filesystem:

docker run -v ~/my_folder:/root ubuntu  ## mount the host machine folder ~/my_folder into the /root directory in the container

#docker-compose #devops #programming #docker #containers

The Essential Docker, Dockerfile, and Docker Compose Cheat Sheet
4.60 GEEK