Skip to content

Instantly share code, notes, and snippets.

@alukach
Last active February 12, 2020 21:32
Show Gist options
  • Save alukach/eb6a91852dd7a4d9db7f1fc62a68abab to your computer and use it in GitHub Desktop.
Save alukach/eb6a91852dd7a4d9db7f1fc62a68abab to your computer and use it in GitHub Desktop.
Docker Cheatsheet

Docker Cheatsheet

Glossary

Container
Single unit of computing.
Task
A docker container running a command.
Service
Many containers performing the same task.
Swarm
A cluster (many servers) distributing services amongst themselves.
Stack
A group of interrelated services that share dependencies, and can be orchestrated and scaled together

Cheatsheet

Build Container Image

docker build <container_image_name> .

Start Container (in foreground)

docker run -it <container_image_name:tag>

Start Container with Environment Variables

docker run -e MYENVVAR=foo <container_image_name:tag>

Or, the following is effectively equal to -e MYENVVAR=$MYENVVAR:

docker run -e MYENVVAR <container_image_name:tag>

Start Container with Environment Variables from EnvFile

docker run -it --env-file <path/to/envfile> <container_image_name:tag>

Start Container (in background)

docker run -d <container_image_name:tag>

List Running Containers

docker container ls

List Running Containers (IDs only)

docker container ls -q

List Most Recently Created Running Container

docker container ls -l

Stop Most Recently Created Running Container

docker container stop $(docker container ls -ql)

Execute a Command in a Running Container

docker exec -it <container_id> ipython

Deploy Stack

docker stack deploy -c docker-compose.yml <stack_name>

Execute a Command within a Stack Service

docker-compose -f docker-compose.yml run <service_name> <cmd>

Get Stack Service Logs

docker service logs <stack_name>_<service_name>

docker service logs cadasta-async_export-worker

Dockerfile

Healthchecks

It is strongly recommended for every Dockerfile to make use of the HEALTHCHECK directive to ensure that malfunctioning containers can be detected and handled.

Amazon ECS Cheatsheet

Glossary

Cluster
A grouping of AWS EC2 instances (referred to as "container instances") that are running the ECS agent. Analagous to a "Swarm" in Docker speak.
Task Definition
A prototype for running a collection of interrelated services (services is referring to the Docker definition of services). Analagous to a "Stack" in Docker speak. Using the ecs-cli, a developer can create Task Definitions from a docker-compose.yml file. Example:
{
  "containerDefinitions": [
    {
      "name": "wordpress",
      "links": [
        "mysql"
      ],
      "image": "wordpress",
      "essential": true,
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 80
        }
      ],
      "memory": 500,
      "cpu": 10
    },
    {
      "environment": [
        {
          "name": "MYSQL_ROOT_PASSWORD",
          "value": "password"
        }
      ],
      "name": "mysql",
      "image": "mysql",
      "cpu": 10,
      "memory": 500,
      "essential": true
    }
 ],
 "family": "wordpress"
}
Service
A long-running task. ECS will maintain a required number of instances running the service and route traffic to services via the AWS Elastic Load Balancing service. Example:
{     
  "cluster": "Wordpress",     
  "serviceName": "wordpress",     
  "taskDefinition": "wordpress:1",     
  "loadBalancers":[],     
  "desiredCount": 1,     
}

Helpful Blogs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment