Show Menu

Docker Basics Cheat Sheet by

Docker Image

docker images
See all available images
docker build -t <na­me>
Create an image with a pretty name (you must define the
in the folder)
docker tag <na­me> userna­me/­rep­osi­tor­y:tag
This tags an image ready to be sent to a repository
docker push userna­me/­rep­osi­tor­y:tag
Push the image to the remote repository
docker search <ke­ywo­rd>
Search for public reposi­tories
Docker Images are the base for
and are similar to
files. They can be for example the image of your app and contain everything needed to run the applic­ation.

These images can be local or in reposi­tories (and marked with an tag)

To create images, you must create a
with some docker commands to specify how that image will be created, for example to setup the enviro­nment and a BaseImage.


Different pieces of the app are called “services” For example, a service for storing applic­ation data in a database, a service for the front-end, etc.

Services are just “conta­iners in produc­tion.” A service only runs one image, but it manages for example what ports it should use and how many replicas of the container should run.

To define a service, you'll need an

For example:
version: "­3"



    image: amiche­let­ti/­get­-st­art­ed:­part1


      replicas: 5



          cpus: "­0.1­"

          memory: 50M


        condition: on-failure


      - "­80:­80"


      - webnet



Here you define the image to be loaded, how many replicas, the resource limits and the restart condit­ions.

To run it you must first start:
docker swarm init

Then run it giving a name:
docker stack deploy -c docker­-co­mpo­se.yml <ap­p_n­ame>

To see the details of containers running in your service, run:
docker stack ps <ap­p_n­ame>

Now each time you request your app (via browser, for example), the load-b­alancer will help you distri­buting the requests to each replica.

To put it down,
docker stack rm <ap­p_n­ame>

This puts down the app, but not the "­one­-no­de" swarm we created. Use:
docker swarm leave --force
Docker Swarm is available only for version "­3"

Docker Container

docker run <im­age>
Run the image, starting a Container
Run in detached mode (in backgr­ound)
-p 4000:80
Maps the port
of the image to the host port
Removes the container when exited
docker ps
List the running containers (you can check container id)
docker ps -l
List all the containers (you can check container id)
docker stop <co­nta­ine­r_i­d>
Stop the container
When you run an image with you are starting a Container, so container is the runtime instance of an
, and consists of the image, an execution enviro­nment and a standart set of instru­ctions.


docker swarm init
Initialize a swarm and become
swarm manager
docker swarm join
Join a swarm as
docker swarm leave --force
Leaves the current swarm
With Docker you can increase resource and capacities by creating a
, which are simply several machines (virtual or physical) running a Docker and joined to a cluster.

Swarms have the
swarm manager
, which can issue docker commands normally, and the
which are only there to provide capacity.


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Docker Cheat Sheet

          More Cheat Sheets by amicheletti