diff --git a/assets/images/docker-compose.png b/assets/images/docker-compose.png new file mode 100644 index 0000000..8aa16d5 Binary files /dev/null and b/assets/images/docker-compose.png differ diff --git a/src/docker-compose/docker-compose.scss b/src/docker-compose/docker-compose.scss new file mode 100644 index 0000000..65706bd --- /dev/null +++ b/src/docker-compose/docker-compose.scss @@ -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; + } + } +} \ No newline at end of file diff --git a/src/docker-compose/first-side/column1.md b/src/docker-compose/first-side/column1.md new file mode 100644 index 0000000..fb45595 --- /dev/null +++ b/src/docker-compose/first-side/column1.md @@ -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` \ No newline at end of file diff --git a/src/docker-compose/first-side/column2.md b/src/docker-compose/first-side/column2.md new file mode 100644 index 0000000..27283af --- /dev/null +++ b/src/docker-compose/first-side/column2.md @@ -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` diff --git a/src/docker-compose/index.html b/src/docker-compose/index.html new file mode 100644 index 0000000..db92b30 --- /dev/null +++ b/src/docker-compose/index.html @@ -0,0 +1,48 @@ + + + + + + + + + + +
+ @@include('../../dist/common/first-side/header.html', {"title": "Docker Compose", "subtitle": "Tool for running multi-container Docker applications", "imageName": "@@folder"}) + +
+
+ @@include('../../dist/@@folder/first-side/column1.html') +
+
+ @@include('../../dist/@@folder/first-side/column2.html') +
+
+ + @@include('../../dist/common/footer.html', {"class": "print-only"}) + + +
+ +
+ +
+ @@include('../../dist/common/reverse/header.html', {"title": "docker-compose cheat sheet", "imageName": "@@folder"}) + +
+
+ @@include('../../dist/@@folder/reverse/column1.html') +
+
+ @@include('../../dist/@@folder/reverse/column2.html') +
+
+ + @@include('../../dist/common/footer.html') +
+ + + + + diff --git a/src/docker-compose/reverse/column1.md b/src/docker-compose/reverse/column1.md new file mode 100644 index 0000000..00f2d6d --- /dev/null +++ b/src/docker-compose/reverse/column1.md @@ -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` diff --git a/src/docker-compose/reverse/column2.md b/src/docker-compose/reverse/column2.md new file mode 100644 index 0000000..584b281 --- /dev/null +++ b/src/docker-compose/reverse/column2.md @@ -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** + diff --git a/src/docker-swarm/first-side/column1.md b/src/docker-swarm/first-side/column1.md index 0727f3a..2f712ec 100644 --- a/src/docker-swarm/first-side/column1.md +++ b/src/docker-swarm/first-side/column1.md @@ -5,7 +5,7 @@ ## On the first Manager node Initialize the cluster -`docker swarm init --advertise-addr ` +`docker swarm init --advertise-addr MANAGER-IP` Retrieve the token to add a new Manager node `docker swarm join-token manager` @@ -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 ` +`docker swarm join --token TOKEN` # Cluster events @@ -26,4 +26,4 @@ Show real time events # Manage networks Create a distributed overlay network -`docker network create --driver overlay ` +`docker network create --driver overlay NETWORK` diff --git a/src/docker-swarm/first-side/column2.md b/src/docker-swarm/first-side/column2.md index 0ef0c02..c021c84 100644 --- a/src/docker-swarm/first-side/column2.md +++ b/src/docker-swarm/first-side/column2.md @@ -4,19 +4,19 @@ List all nodes `docker node ls` Inspect a node -`docker node inspect ` +`docker node inspect NODE` List tasks running on a node -`docker node ps ` +`docker node ps NODE` Promote a node to Manager -`docker node promote ` +`docker node promote NODE` Demote a node to Worker -`docker node demote ` +`docker node demote NODE` Update a node -`docker node update [OPTIONS] ` +`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` @@ -25,4 +25,4 @@ Make a Worker node leave the Cluster `docker swarm leave` Remove a node from nodes list -`docker node rm ` +`docker node rm NODE` diff --git a/src/docker-swarm/reverse/column1.md b/src/docker-swarm/reverse/column1.md index 5de11e0..4470a27 100644 --- a/src/docker-swarm/reverse/column1.md +++ b/src/docker-swarm/reverse/column1.md @@ -1,7 +1,7 @@ # Manage services Create a new service -`docker service create [OPTIONS] [COMMAND] [ARGS...]` +`docker service create [options] IMAGE [COMMAND] [ARGS...]` * Create a busybox service: `docker service create --name busybox busybox` @@ -9,25 +9,25 @@ List all services `docker service ls` List the tasks of a service -`docker service ps ` +`docker service ps SERVICE` Remove a service -`docker service rm ` +`docker service rm SERVICE` Update a service -`docker service update [OPTIONS] ` +`docker service update [options] SERVICE` * Update service image `docker service update --image my-service:2 my-service` Scale a service -`docker service scale =` +`docker service scale SERVICE=REPLICAS` Inspect a service -`docker service inspect ` +`docker service inspect SERVICE` Fetch the logs of a service or task -`docker service logs ` -`docker service logs ` +`docker service logs SERVICE` +`docker service logs TASK` Roll back a service to its previous version -`docker service rollback ` +`docker service rollback SERVICE` diff --git a/src/docker-swarm/reverse/column2.md b/src/docker-swarm/reverse/column2.md index 030098a..6ee8bd9 100644 --- a/src/docker-swarm/reverse/column2.md +++ b/src/docker-swarm/reverse/column2.md @@ -1,25 +1,25 @@ # Manage stacks Deploy a new stack from a compose file -`docker stack deploy --compose-file ` +`docker stack deploy --compose-file COMPOSE-FILE STACK` List all stacks `docker stack ls` List the services of a stack -`docker stack services ` +`docker stack services STACK` List the tasks of a stack -`docker stack ps ` +`docker stack ps STACK` Remove a stack -`docker stack rm ` +`docker stack rm STACK` # Manage secrets Create a secret from a file or STDIN -`Docker secret create ` -`echo |docker secret create ` +`Docker secret create SECRET-NAME FILE-PATH` +`echo STRING |docker secret create SECRET-NAME` List all secrets `Docker secret ls` diff --git a/src/docker/first-side/column1.md b/src/docker/first-side/column1.md index 3287bb9..e74e642 100644 --- a/src/docker/first-side/column1.md +++ b/src/docker/first-side/column1.md @@ -1,4 +1,4 @@ - docker version: __17.05+__ - Date: __June 2017__ + docker version: __17.09+__ - Date: __October 2017__ # Installation @@ -11,10 +11,10 @@ Show the Docker version information # Start containers Run a container -`docker run ` +`docker run [options] IMAGE [COMMAND]` Run a container in background -`docker run -d ` +`docker run -d IMAGE [COMMAND]` # Manage containers @@ -25,13 +25,13 @@ List all containers `docker ps -a` Restart container -`docker restart ` +`docker restart [options] CONTAINER` Stop a running container -`docker stop ` +`docker stop CONTAINER` Remove a container -`docker rm ` +`docker rm CONTAINER` Remove all containers `docker rm $(docker ps -a -q)` diff --git a/src/docker/first-side/column2.md b/src/docker/first-side/column2.md index fdb5cec..23c128f 100644 --- a/src/docker/first-side/column2.md +++ b/src/docker/first-side/column2.md @@ -1,37 +1,37 @@ # Manage images Build an image from a Dockerfile -`docker build -t -f ` +`docker build -t IMAGE:TAG -f PATH` Search an image on Dockerhub -`docker search ` +`docker search IMAGE` Pull an image from Dockerhub -`docker pull ` +`docker pull [options] IMAGE[:TAG]` List all local images `docker images` Remove an image -`docker rmi ` +`docker rmi [options] [IMAGE]` Remove all images `docker rmi $(docker images -q)` Login to a registry -`docker login ` +`docker login [options] [SERVER]` Pull an image from a registry -`docker pull /` +`docker pull [options] SERVER/NAME[:TAG]` Push an image to a registry -`docker push /` +`docker push SERVER/NAME[:TAG]` Save container state to an image -`docker commit