Skip to content

Commit

Permalink
Merge pull request #12 from mpoullain/docker-compose
Browse files Browse the repository at this point in the history
Add a new cheat sheet for Docker Compose
  • Loading branch information
lrivallain authored Oct 23, 2017
2 parents 40f12c3 + fa531e0 commit 655cc09
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 55 deletions.
Binary file added assets/images/docker-compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/docker-compose/docker-compose.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* put your all custom css rules here */
/* you must not change other scss files */

body {
// available colors are: blue, green, purple, orange and grey
--currentColor: var(--blue);

main div {
img {
height: 230px;
}
}
}
32 changes: 32 additions & 0 deletions src/docker-compose/first-side/column1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
docker-compose version: __1.16.1__ - Date: __October 2017__

# Info

Show the docker-compose version
`docker-compose version`

Display help and usage instructions for a command
`docker-compose help`

# Manage containers

Build, (re)create and start containers
`docker-compose up [options] [SERVICE]`

* Start all containers in background: `docker-compose up -d`

Stop containers and remove containers, networks, volumes, and images created.
`docker-compose down [options]`

Restart all stopped and running services
`docker-compose restart [options] [SERVICE]`

Create containers (without starting them)
`docker-compose create [options] [SERVICE]`

* Build images before creating containers: `docker-compose create --build`

Removes stopped service containers
`docker-compose rm [options] [SERVICE]`

* Stop the containers, if required, before removing: `docker-compose rm --stop`
26 changes: 26 additions & 0 deletions src/docker-compose/first-side/column2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Set the number of containers to run for an existing service
`docker-compose scale SERVICE=NUM`

* Scale the service web with 3 containers: `docker-compose scale web=3`

Start existing containers for a service
`docker-compose start SERVICE`

Stop running containers (without removing them)
`docker-compose stop SERVICE`

Pause running containers of a service
`docker-compose pause SERVICE`

Unpause paused containers of a service
`docker-compose unpause SERVICE`

Run a one-time command against a service
`docker-compose run [options] SERVICE [COMMAND]`

* Start the web service and runs bash as its command: `docker-compose run web bash`

Force running containers to stop by sending a SIGKILL signal
`docker-compose kill [options] [SERVICE]`

* Kill all containers with SIGINT signal: `docker-compose kill -s SIGINT`
48 changes: 48 additions & 0 deletions src/docker-compose/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Droid+Sans:700" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="../common.css">
<link rel="stylesheet" href="../common/lib/atom-one-light.css">
<link rel="stylesheet" href="./@@folder.css">
</head>
<body>
<input type="checkbox" id="showPreview"/>
<div class="first-side">
@@include('../../dist/common/first-side/header.html', {"title": "Docker Compose", "subtitle": "Tool for running multi-container Docker applications", "imageName": "@@folder"})

<main>
<div class="column1">
@@include('../../dist/@@folder/first-side/column1.html')
</div>
<div class="column2">
@@include('../../dist/@@folder/first-side/column2.html')
</div>
</main>

@@include('../../dist/common/footer.html', {"class": "print-only"})


</div>

<hr class="no-print"/>

<div class="reverse">
@@include('../../dist/common/reverse/header.html', {"title": "docker-compose cheat sheet", "imageName": "@@folder"})

<main>
<div class="column1">
@@include('../../dist/@@folder/reverse/column1.html')
</div>
<div class="column2">
@@include('../../dist/@@folder/reverse/column2.html')
</div>
</main>

@@include('../../dist/common/footer.html')
</div>

<script src="../common/lib/highlight.pack.js"></script>
<script src="../common/script.js"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions src/docker-compose/reverse/column1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Manage Images

Build images referenced in Compose file (without starting the containers)
`docker-compose build [options] [SERVICE]`

Pull images referenced in Compose file
`docker-compose pull [options] [SERVICE]`

Push images for services to their respective registry/repository
`docker-compose push [options] [SERVICE]`

# Tools

Validate and view the Compose file
`docker-compose config`

List containers
`docker-compose ps [options] [SERVICE]`

Display log output from services
`docker-compose logs [options] [SERVICE]`

Display the running processes
`docker-compose top [SERVICE]`

Stream container events for every container
`docker-compose events [options] [SERVICE]`

List images used by the created containers
`docker-compose images`

Run arbitrary commands in the containers of a service
`docker-compose exec [options] SERVICE COMMAND`

Print the public port for a port binding
`docker-compose port [options] SERVICE PRIVATE_PORT`
48 changes: 48 additions & 0 deletions src/docker-compose/reverse/column2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Compose File Example

Deploying Wordpress with docker-compose :

`docker-compose.yml`

```yaml
version: '3'

services:

db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress

volumes:
db_data:
```
Using :
* version **3** of compose file
* **2 services** (db and wordpress)
* **restart policies** for containers
* **ports** to access web interface
* **environment variables** to initialize the database and allow wordpress to connect
* **volume** to store data
* **name of service** as DNS entry for **WORDPRESS_DB_HOST**
6 changes: 3 additions & 3 deletions src/docker-swarm/first-side/column1.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## On the first Manager node

Initialize the cluster
`docker swarm init --advertise-addr <MANAGER-IP>`
`docker swarm init --advertise-addr MANAGER-IP`

Retrieve the token to add a new Manager node
`docker swarm join-token manager`
Expand All @@ -16,7 +16,7 @@ Retrieve the token to add a new Worker node
## On every new node

Join the node to the cluster
`docker swarm join --token <TOKEN>`
`docker swarm join --token TOKEN`

# Cluster events

Expand All @@ -26,4 +26,4 @@ Show real time events
# Manage networks

Create a distributed overlay network
`docker network create --driver overlay <NETWORK>`
`docker network create --driver overlay NETWORK`
12 changes: 6 additions & 6 deletions src/docker-swarm/first-side/column2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ List all nodes
`docker node ls`

Inspect a node
`docker node inspect <NODE>`
`docker node inspect NODE`

List tasks running on a node
`docker node ps <NODE>`
`docker node ps NODE`

Promote a node to Manager
`docker node promote <NODE>`
`docker node promote NODE`

Demote a node to Worker
`docker node demote <NODE>`
`docker node demote NODE`

Update a node
`docker node update [OPTIONS] <NODE>`
`docker node update [options] NODE`

* Add a label: `docker node update --label-add type=front node-1`
* Drain a node: `docker node update --availability drain node-1`
Expand All @@ -25,4 +25,4 @@ Make a Worker node leave the Cluster
`docker swarm leave`

Remove a node from nodes list
`docker node rm <NODE>`
`docker node rm NODE`
18 changes: 9 additions & 9 deletions src/docker-swarm/reverse/column1.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Manage services

Create a new service
`docker service create [OPTIONS] <IMAGE> [COMMAND] [ARGS...]`
`docker service create [options] IMAGE [COMMAND] [ARGS...]`

* Create a busybox service: `docker service create --name busybox busybox`

List all services
`docker service ls`

List the tasks of a service
`docker service ps <SERVICE>`
`docker service ps SERVICE`

Remove a service
`docker service rm <SERVICE>`
`docker service rm SERVICE`

Update a service
`docker service update [OPTIONS] <service>`
`docker service update [options] SERVICE`

* Update service image `docker service update --image my-service:2 my-service`

Scale a service
`docker service scale <SERVICE>=<REPLICAS>`
`docker service scale SERVICE=REPLICAS`

Inspect a service
`docker service inspect <SERVICE>`
`docker service inspect SERVICE`

Fetch the logs of a service or task
`docker service logs <SERVICE>`
`docker service logs <TASK>`
`docker service logs SERVICE`
`docker service logs TASK`

Roll back a service to its previous version
`docker service rollback <SERVICE>`
`docker service rollback SERVICE`
12 changes: 6 additions & 6 deletions src/docker-swarm/reverse/column2.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Manage stacks

Deploy a new stack from a compose file
`docker stack deploy --compose-file <COMPOSE-FILE> <STACK>`
`docker stack deploy --compose-file COMPOSE-FILE STACK`

List all stacks
`docker stack ls`

List the services of a stack
`docker stack services <STACK>`
`docker stack services STACK`

List the tasks of a stack
`docker stack ps <STACK>`
`docker stack ps STACK`

Remove a stack
`docker stack rm <STACK>`
`docker stack rm STACK`

# Manage secrets

Create a secret from a file or STDIN
`Docker secret create <SECRET-NAME> <FILE-PATH>`
`echo <STRING> |docker secret create <SECRET-NAME>`
`Docker secret create SECRET-NAME FILE-PATH`
`echo STRING |docker secret create SECRET-NAME`

List all secrets
`Docker secret ls`
Expand Down
12 changes: 6 additions & 6 deletions src/docker/first-side/column1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker version: __17.05+__ - Date: __June 2017__
docker version: __17.09+__ - Date: __October 2017__

# Installation

Expand All @@ -11,10 +11,10 @@ Show the Docker version information
# Start containers

Run a container
`docker run <options> <image> <command>`
`docker run [options] IMAGE [COMMAND]`

Run a container in background
`docker run -d <image> <command>`
`docker run -d IMAGE [COMMAND]`

# Manage containers

Expand All @@ -25,13 +25,13 @@ List all containers
`docker ps -a`

Restart container
`docker restart <container>`
`docker restart [options] CONTAINER`

Stop a running container
`docker stop <container>`
`docker stop CONTAINER`

Remove a container
`docker rm <container>`
`docker rm CONTAINER`

Remove all containers
`docker rm $(docker ps -a -q)`
Loading

0 comments on commit 655cc09

Please sign in to comment.