docs: update docs of README.mds.

summary: update command docker compose to docker-compose.
This commit is contained in:
Mark 2023-01-05 22:29:01 +08:00
parent 20e3e4c434
commit 4b0c67e2aa
40 changed files with 518 additions and 332 deletions

View File

@ -10,6 +10,7 @@ These samples provide a starting point for how to integrate different services u
> The following samples are intended for use in local development environments such as project setups, tinkering with software stacks, etc. These samples must not be deployed in production environments. > The following samples are intended for use in local development environments such as project setups, tinkering with software stacks, etc. These samples must not be deployed in production environments.
<!--lint disable awesome-toc--> <!--lint disable awesome-toc-->
## Contents ## Contents
- [Samples of Docker Compose applications with multiple integrated services](#samples-of-docker-compose-applications-with-multiple-integrated-services). - [Samples of Docker Compose applications with multiple integrated services](#samples-of-docker-compose-applications-with-multiple-integrated-services).
@ -99,7 +100,7 @@ describes the configuration of service components. All samples can be run in
a local environment by going into the root directory of each one and executing: a local environment by going into the root directory of each one and executing:
```console ```console
docker compose up -d docker-compose up -d
``` ```
Check the `README.md` of each sample to get more details on the structure and Check the `README.md` of each sample to get more details on the structure and
@ -107,7 +108,7 @@ what is the expected output.
To stop and remove all containers of the sample application run: To stop and remove all containers of the sample application run:
```console ```console
docker compose down docker-compose down
``` ```
### Quickstart guides ### Quickstart guides
@ -115,6 +116,7 @@ docker compose down
In addition to all the ready to run Compose samples listed above the folder [official-documentation-samples](official-documentation-samples/README.md) contains quickstart guides. Each of these step by step guides explain which files need to be created to build and run a Docker Compose application. In addition to all the ready to run Compose samples listed above the folder [official-documentation-samples](official-documentation-samples/README.md) contains quickstart guides. Each of these step by step guides explain which files need to be created to build and run a Docker Compose application.
<!--lint disable awesome-toc--> <!--lint disable awesome-toc-->
## Contribute ## Contribute
We welcome examples that help people understand how to use Docker Compose for We welcome examples that help people understand how to use Docker Compose for

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Angular service ### Angular service
Project structure: Project structure:
``` ```
. .
├── angular ├── angular
@ -20,6 +21,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -29,16 +31,16 @@ services:
... ...
``` ```
The compose file defines an application with one service `angular`. The image for the service is built with the Dockerfile inside the `angular` directory (build parameter). The compose file defines an application with one service `angular`. The image for the service is built with the Dockerfile inside the `angular` directory (build parameter).
When deploying the application, docker compose maps the container port 4200 to the same port on the host as specified in the file. When deploying the application, docker compose maps the container port 4200 to the same port on the host as specified in the file.
Make sure port 4200 is not being used by another container, otherwise the port should be changed. Make sure port 4200 is not being used by another container, otherwise the port should be changed.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "angular_default" with the default driver Creating network "angular_default" with the default driver
Building angular Building angular
Step 1/7 : FROM node:10 Step 1/7 : FROM node:10
@ -52,10 +54,10 @@ WARNING: Image for service web was built because it did not already exist. To re
Creating angular_web_1 ... done Creating angular_web_1 ... done
``` ```
## Expected result ## Expected result
Listing containers must show a container running and the port mapping as below: Listing containers must show a container running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -70,5 +72,5 @@ After the application starts, navigate to `http://localhost:4200` in your web br
Stop and remove the container Stop and remove the container
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### PHP application with Apache2 ### PHP application with Apache2
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -19,6 +20,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -32,7 +34,7 @@ services:
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "php-docker_web" with the default driver Creating network "php-docker_web" with the default driver
Building web Building web
Step 1/6 : FROM php:7.2-apache Step 1/6 : FROM php:7.2-apache
@ -45,6 +47,7 @@ Creating php-docker_web_1 ... done
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -52,12 +55,14 @@ CONTAINER ID IMAGE COMMAND CREATE
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
``` ```
$ curl localhost:80 $ curl localhost:80
Hello World! Hello World!
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -1,6 +1,7 @@
## Compose sample application: ASP.NET with MS SQL server database ## Compose sample application: ASP.NET with MS SQL server database
Project structure: Project structure:
``` ```
. .
├── app ├── app
@ -13,6 +14,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -26,6 +28,7 @@ services:
#image: mcr.microsoft.com/mssql/server #image: mcr.microsoft.com/mssql/server
... ...
``` ```
The compose file defines an application with two services `web` and `db`. The image for the web service is built with the Dockerfile inside the `app` directory (build parameter). The compose file defines an application with two services `web` and `db`. The image for the web service is built with the Dockerfile inside the `app` directory (build parameter).
When deploying the application, docker compose maps the container port 80 to port 80 of the host as specified in the file. When deploying the application, docker compose maps the container port 80 to port 80 of the host as specified in the file.
@ -39,7 +42,7 @@ Make sure port 80 on the host is not being used by another container, otherwise
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "aspnet-mssql_default" with the default driver Creating network "aspnet-mssql_default" with the default driver
Building web Building web
Step 1/13 : FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build Step 1/13 : FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
@ -53,10 +56,10 @@ Creating aspnet-mssql_web_1 ... done
Creating aspnet-mssql_db_1 ... done Creating aspnet-mssql_db_1 ... done
``` ```
## Expected result ## Expected result
Listing containers must show two containers running and the port mapping as below: Listing containers must show two containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -71,5 +74,5 @@ After the application starts, navigate to `http://localhost:80` in your web brow
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Django application in dev mode ### Django application in dev mode
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -20,6 +21,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -31,7 +33,7 @@ services:
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "django_default" with the default driver Creating network "django_default" with the default driver
Building web Building web
Step 1/6 : FROM python:3.7-alpine Step 1/6 : FROM python:3.7-alpine
@ -45,6 +47,7 @@ Creating django_web_1 ... done
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -54,6 +57,7 @@ CONTAINER ID IMAGE COMMAND CREATED
After the application starts, navigate to `http://localhost:8000` in your web browser: After the application starts, navigate to `http://localhost:8000` in your web browser:
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -1,13 +1,16 @@
## Compose sample application ## Compose sample application
### Elasticsearch, Logstash, and Kibana (ELK) in single-node ### Elasticsearch, Logstash, and Kibana (ELK) in single-node
Project structure: Project structure:
``` ```
. .
└── compose.yaml └── compose.yaml
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
elasticsearch: elasticsearch:
@ -24,7 +27,7 @@ services:
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "elasticsearch-logstash-kibana_elastic" with driver "bridge" Creating network "elasticsearch-logstash-kibana_elastic" with driver "bridge"
Creating es ... done Creating es ... done
Creating log ... done Creating log ... done
@ -34,6 +37,7 @@ Creating kib ... done
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -44,13 +48,14 @@ b448fd3e9b30 kibana:7.8.0 "/usr/local/bin/dumb…" 43 seconds
After the application starts, navigate to below links in your web browser: After the application starts, navigate to below links in your web browser:
* Elasticsearch: [`http://localhost:9200`](http://localhost:9200) - Elasticsearch: [`http://localhost:9200`](http://localhost:9200)
* Logstash: [`http://localhost:9600`](http://localhost:9600) - Logstash: [`http://localhost:9600`](http://localhost:9600)
* Kibana: [`http://localhost:5601/api/status`](http://localhost:5601/api/status) - Kibana: [`http://localhost:5601/api/status`](http://localhost:5601/api/status)
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```
## Attribution ## Attribution

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Python/FastAPI application ### Python/FastAPI application
Project structure: Project structure:
``` ```
├── compose.yaml ├── compose.yaml
├── Dockerfile ├── Dockerfile
@ -20,6 +21,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
api: api:
@ -38,9 +40,11 @@ services:
```shell ```shell
docker-compose up -d --build docker-compose up -d --build
``` ```
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -48,6 +52,7 @@ CONTAINER ID IMAGE COMMAND CREATED STATUS
``` ```
After the application starts, navigate to `http://localhost:8000` in your web browser and you should see the following json response: After the application starts, navigate to `http://localhost:8000` in your web browser and you should see the following json response:
``` ```
{ {
"message": "OK" "message": "OK"
@ -55,6 +60,7 @@ After the application starts, navigate to `http://localhost:8000` in your web br
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -40,7 +40,7 @@ services:
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
[+] Running 24/24 [+] Running 24/24
⠿ redis Pulled ⠿ redis Pulled
... ...
@ -56,15 +56,17 @@ $ docker compose up -d
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker compose ps $ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS NAME COMMAND SERVICE STATUS PORTS
flask-redis-redis-1 "redis-server --load…" redis running 0.0.0.0:6379->6379/tcp flask-redis-redis-1 "redis-server --load…" redis running 0.0.0.0:6379->6379/tcp
flask-redis-web-1 "/bin/sh -c 'python …" web running 0.0.0.0:8000->8000/tcp flask-redis-web-1 "/bin/sh -c 'python …" web running 0.0.0.0:8000->8000/tcp
``` ```
After the application starts, navigate to `http://localhost:8000` in your web browser or run: After the application starts, navigate to `http://localhost:8000` in your web browser or run:
``` ```
$ curl localhost:8000 $ curl localhost:8000
This webpage has been viewed 2 time(s) This webpage has been viewed 2 time(s)
@ -72,7 +74,8 @@ This webpage has been viewed 2 time(s)
## Monitoring Redis keys ## Monitoring Redis keys
Connect to redis database by using ```redis-cli``` command and monitor the keys. Connect to redis database by using `redis-cli` command and monitor the keys.
``` ```
redis-cli -p 6379 redis-cli -p 6379
127.0.0.1:6379> monitor 127.0.0.1:6379> monitor
@ -81,8 +84,8 @@ OK
1646634062.735669 [0 172.21.0.3:33106] "GET" "hits" 1646634062.735669 [0 172.21.0.3:33106] "GET" "hits"
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Python/Flask application ### Python/Flask application
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -20,6 +21,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -33,7 +35,7 @@ services:
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
[+] Building 1.1s (16/16) FINISHED [+] Building 1.1s (16/16) FINISHED
=> [internal] load build definition from Dockerfile 0.0s => [internal] load build definition from Dockerfile 0.0s
... 0.0s ... 0.0s
@ -46,19 +48,22 @@ $ docker compose up -d
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker compose ps $ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS NAME COMMAND SERVICE STATUS PORTS
flask-web-1 "python3 app.py" web running 0.0.0.0:8000->8000/tcp flask-web-1 "python3 app.py" web running 0.0.0.0:8000->8000/tcp
``` ```
After the application starts, navigate to `http://localhost:8000` in your web browser or run: After the application starts, navigate to `http://localhost:8000` in your web browser or run:
``` ```
$ curl localhost:8000 $ curl localhost:8000
Hello World! Hello World!
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -1,8 +1,9 @@
## Gitea with PostgreSQL ## Gitea with PostgreSQL
This example defines one of the base setups for Gitea. More details on how to customize the installation and the compose file can be found in [Gitea documentation](https://docs.gitea.io/en-us/install-with-docker/). This example defines one of the base setups for Gitea. More details on how to customize the installation and the compose file can be found in [Gitea documentation](https://docs.gitea.io/en-us/install-with-docker/).
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -10,6 +11,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
gitea: gitea:
@ -29,7 +31,7 @@ the same port of the host as specified in the compose file.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "gitea-postgres_default" with the default driver Creating network "gitea-postgres_default" with the default driver
Creating gitea-postgres_db_1 ... done Creating gitea-postgres_db_1 ... done
Creating gitea-postgres_gitea_1 ... done Creating gitea-postgres_gitea_1 ... done
@ -39,10 +41,10 @@ Starting gitea-postgres_db_1 ... done
Starting gitea-postgres_gitea_1 ... done Starting gitea-postgres_gitea_1 ... done
``` ```
## Expected result ## Expected result
Check containers are running and the port mapping: Check containers are running and the port mapping:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -58,10 +60,11 @@ Gitea service.
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```
To remove all Gitea data, delete the named volumes by passing the `-v` parameter: To remove all Gitea data, delete the named volumes by passing the `-v` parameter:
``` ```
$ docker compose down -v $ docker-compose down -v
``` ```

View File

@ -1,7 +1,9 @@
## Minecraft server ## Minecraft server
This example defines a basic setup for a Minecraft server. More details on the Minecraft server docker image can be found [here](https://github.com/itzg/docker-minecraft-server/blob/master/README.md). This example defines a basic setup for a Minecraft server. More details on the Minecraft server docker image can be found [here](https://github.com/itzg/docker-minecraft-server/blob/master/README.md).
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -9,6 +11,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
minecraft: minecraft:
@ -28,7 +31,7 @@ This example maps the Minecraft data folder holding all game storage to ~/minecr
``` ```
$ mkdir -p ~/minecraft_data $ mkdir -p ~/minecraft_data
$ docker compose up -d $ docker-compose up -d
WARNING: Some services (minecraft) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm. WARNING: Some services (minecraft) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Creating network "minecraft_default" with the default driver Creating network "minecraft_default" with the default driver
Creating minecraft_minecraft_1 ... done Creating minecraft_minecraft_1 ... done
@ -49,7 +52,7 @@ CONTAINER ID IMAGE COMMAND CREATED
After running `docker-compose up`, the minecraft server takes a bit of time to initialize Minecraft world. You can follow the progress: After running `docker-compose up`, the minecraft server takes a bit of time to initialize Minecraft world. You can follow the progress:
``` ```
$ docker compose logs $ docker-compose logs
... ...
minecraft_1 | [15:06:39] [Worker-Main-6/INFO]: Preparing spawn area: 94% minecraft_1 | [15:06:39] [Worker-Main-6/INFO]: Preparing spawn area: 94%
minecraft_1 | [15:06:39] [Worker-Main-7/INFO]: Preparing spawn area: 94% minecraft_1 | [15:06:39] [Worker-Main-7/INFO]: Preparing spawn area: 94%
@ -72,11 +75,11 @@ Once it is initialized, run your Minecraft application, hit "Play", then "Multip
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```
To delete all data, remove all named volumes by passing the -v arguments: To delete all data, remove all named volumes by passing the -v arguments:
``` ```
$ docker compose down -v $ docker-compose down -v
``` ```

View File

@ -1,10 +1,11 @@
## Nextcloud with Postgres database ## Nextcloud with Postgres database
This example defines one of the base setups for Nextcloud. More details on how to This example defines one of the base setups for Nextcloud. More details on how to
further customize the installation and the compose file can be found on the further customize the installation and the compose file can be found on the
[official image page](https://hub.docker.com/_/nextcloud). [official image page](https://hub.docker.com/_/nextcloud).
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -12,6 +13,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
nc: nc:
@ -30,7 +32,7 @@ port 80 of the host as specified in the compose file.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "nextcloud-postgres_default" with the default driver Creating network "nextcloud-postgres_default" with the default driver
Creating volume "nextcloud-postgres_nc_data" with default driver Creating volume "nextcloud-postgres_nc_data" with default driver
Pulling nc (nextcloud:apache)... Pulling nc (nextcloud:apache)...
@ -41,10 +43,10 @@ Creating nextcloud-postgres_nc_1 ... done
Creating nextcloud-postgres_db_1 ... done Creating nextcloud-postgres_db_1 ... done
``` ```
## Expected result ## Expected result
Check containers are running and the port mapping: Check containers are running and the port mapping:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -60,5 +62,5 @@ Nextcloud service.
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -1,10 +1,11 @@
## Nextcloud with Redis and MariaDB ## Nextcloud with Redis and MariaDB
This example defines one of the basic setups for Nextcloud. More details on how to This example defines one of the basic setups for Nextcloud. More details on how to
further customize the installation and the compose file can be found on the further customize the installation and the compose file can be found on the
[official image page](https://hub.docker.com/_/nextcloud). [official image page](https://hub.docker.com/_/nextcloud).
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -12,6 +13,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
nc: nc:
@ -35,7 +37,7 @@ port 80 of the host as specified in the compose file.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "nextcloud-redis-mariadb_redisnet" with the default driver Creating network "nextcloud-redis-mariadb_redisnet" with the default driver
Creating network "nextcloud-redis-mariadb_dbnet" with the default driver Creating network "nextcloud-redis-mariadb_dbnet" with the default driver
Creating volume "nextcloud-redis-mariadb_nc_data" with default driver Creating volume "nextcloud-redis-mariadb_nc_data" with default driver
@ -48,10 +50,10 @@ Creating nextcloud-redis-mariadb_nc_1 ... done
Creating nextcloud-redis-mariadb_redis_1 ... done Creating nextcloud-redis-mariadb_redis_1 ... done
``` ```
## Expected result ## Expected result
Check containers are running and the port mapping: Check containers are running and the port mapping:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -68,10 +70,11 @@ Nextcloud service.
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```
To delete all data, remove all named volumes by passing the `-v` arguments: To delete all data, remove all named volumes by passing the `-v` arguments:
``` ```
$ docker compose down -v $ docker-compose down -v
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### ASP.NET server with an Nginx proxy and a MySQL database ### ASP.NET server with an Nginx proxy and a MySQL database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -25,6 +26,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -43,6 +45,7 @@ services:
- 80:80 - 80:80
... ...
``` ```
The compose file defines an application with three services `proxy`, `backend` and `db`. The compose file defines an application with three services `proxy`, `backend` and `db`.
When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file.
Make sure port 80 on the host is not already being in use. Make sure port 80 on the host is not already being in use.
@ -55,12 +58,13 @@ Make sure port 80 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
``` ```
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -73,12 +77,14 @@ l_db_1
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
``` ```
$ curl localhost:80 $ curl localhost:80
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"] ["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Python/Flask application with Nginx proxy and a Mongo database ### Python/Flask application with Nginx proxy and a Mongo database
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -22,6 +23,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -34,6 +36,7 @@ services:
mongo: mongo:
image: mongo image: mongo
``` ```
The compose file defines an application with three services `web`, `backend` and `db`. The compose file defines an application with three services `web`, `backend` and `db`.
When deploying the application, docker compose maps port 80 of the web service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 80 of the web service container to port 80 of the host as specified in the file.
Make sure port 80 on the host is not being used by another container, otherwise the port should be changed. Make sure port 80 on the host is not being used by another container, otherwise the port should be changed.
@ -41,7 +44,7 @@ Make sure port 80 on the host is not being used by another container, otherwise
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "nginx-flask-mongo_default" with the default driver Creating network "nginx-flask-mongo_default" with the default driver
Pulling mongo (mongo:)... Pulling mongo (mongo:)...
latest: Pulling from library/mongo latest: Pulling from library/mongo
@ -58,6 +61,7 @@ Creating nginx-flask-mongo_web_1 ... done
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -67,12 +71,14 @@ d7eea5481c77 mongo "docker-entrypoint.s…" About
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
``` ```
$ curl localhost:80 $ curl localhost:80
Hello from the MongoDB client! Hello from the MongoDB client!
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Python/Flask with Nginx proxy and MySQL database ### Python/Flask with Nginx proxy and MySQL database
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -22,6 +23,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -39,6 +41,7 @@ services:
build: proxy build: proxy
... ...
``` ```
The compose file defines an application with three services `proxy`, `backend` and `db`. The compose file defines an application with three services `proxy`, `backend` and `db`.
When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file.
Make sure port 80 on the host is not already being in use. Make sure port 80 on the host is not already being in use.
@ -51,7 +54,7 @@ Make sure port 80 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "nginx-flask-mysql_default" with the default driver Creating network "nginx-flask-mysql_default" with the default driver
Pulling db (mysql:8.0.19)... Pulling db (mysql:8.0.19)...
5.7: Pulling from library/mysql 5.7: Pulling from library/mysql
@ -66,8 +69,9 @@ Creating nginx-flask-mysql_proxy_1 ... done
## Expected result ## Expected result
Listing containers should show three containers running and the port mapping as below: Listing containers should show three containers running and the port mapping as below:
``` ```
$ docker compose ps $ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS NAME COMMAND SERVICE STATUS PORTS
nginx-flask-mysql-backend-1 "flask run" backend running 0.0.0.0:8000->8000/tcp nginx-flask-mysql-backend-1 "flask run" backend running 0.0.0.0:8000->8000/tcp
nginx-flask-mysql-db-1 "docker-entrypoint.s…" db running (healthy) 3306/tcp, 33060/tcp nginx-flask-mysql-db-1 "docker-entrypoint.s…" db running (healthy) 3306/tcp, 33060/tcp
@ -75,12 +79,14 @@ nginx-flask-mysql-proxy-1 "nginx -g 'daemon of…" proxy run
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
``` ```
$ curl localhost:80 $ curl localhost:80
<div>Blog post #1</div><div>Blog post #2</div><div>Blog post #3</div><div>Blog post #4</div> <div>Blog post #1</div><div>Blog post #2</div><div>Blog post #3</div><div>Blog post #4</div>
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Go server with an Nginx proxy and a MariaDB/MySQL database ### Go server with an Nginx proxy and a MariaDB/MySQL database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -25,6 +26,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```yaml ```yaml
services: services:
backend: backend:
@ -49,6 +51,7 @@ services:
- 80:80 - 80:80
... ...
``` ```
The compose file defines an application with three services `proxy`, `backend` and `db`. The compose file defines an application with three services `proxy`, `backend` and `db`.
When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file.
Make sure port 80 on the host is not already being in use. Make sure port 80 on the host is not already being in use.
@ -61,7 +64,7 @@ Make sure port 80 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
```shell ```shell
$ docker compose up -d $ docker-compose up -d
Creating network "nginx-golang-mysql_default" with the default driver Creating network "nginx-golang-mysql_default" with the default driver
Building backend Building backend
Step 1/8 : FROM golang:1.13-alpine AS build Step 1/8 : FROM golang:1.13-alpine AS build
@ -78,8 +81,9 @@ Creating nginx-golang-mysql_proxy_1 ... done
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
```shell ```shell
$ docker compose ps $ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS NAME COMMAND SERVICE STATUS PORTS
nginx-golang-mysql-backend-1 "/code/bin/backend" backend running nginx-golang-mysql-backend-1 "/code/bin/backend" backend running
nginx-golang-mysql-db-1 "docker-entrypoint.s…" db running (healthy) 3306/tcp nginx-golang-mysql-db-1 "docker-entrypoint.s…" db running (healthy) 3306/tcp
@ -88,12 +92,14 @@ l_db_1
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
```shell ```shell
$ curl localhost:80 $ curl localhost:80
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"] ["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
``` ```
Stop and remove the containers Stop and remove the containers
```shell ```shell
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Go server with an Nginx proxy and a Postgres database ### Go server with an Nginx proxy and a Postgres database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -25,6 +26,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```shell ```shell
services: services:
backend: backend:
@ -46,6 +48,7 @@ services:
- 80:80 - 80:80
... ...
``` ```
The compose file defines an application with three services `proxy`, `backend` and `db`. The compose file defines an application with three services `proxy`, `backend` and `db`.
When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 80 of the proxy service container to port 80 of the host as specified in the file.
Make sure port 80 on the host is not already being in use. Make sure port 80 on the host is not already being in use.
@ -53,7 +56,7 @@ Make sure port 80 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
```shell ```shell
$ docker compose up -d $ docker-compose up -d
Creating network "nginx-golang-postgres_default" with the default driver Creating network "nginx-golang-postgres_default" with the default driver
Pulling db (postgres:)... Pulling db (postgres:)...
latest: Pulling from library/postgres latest: Pulling from library/postgres
@ -69,8 +72,9 @@ Creating nginx-golang-postgres_proxy_1 ... done
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
```shell ```shell
$ docker compose ps $ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS NAME COMMAND SERVICE STATUS PORTS
nginx-golang-postgres-backend-1 "/code/bin/backend" backend running nginx-golang-postgres-backend-1 "/code/bin/backend" backend running
nginx-golang-postgres-db-1 "docker-entrypoint.s…" db running (healthy) 5432/tcp nginx-golang-postgres-db-1 "docker-entrypoint.s…" db running (healthy) 5432/tcp
@ -78,12 +82,14 @@ nginx-golang-postgres-proxy-1 "/docker-entrypoint.…" proxy
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
```shell ```shell
$ curl localhost:80 $ curl localhost:80
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"] ["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
``` ```
Stop and remove the containers Stop and remove the containers
```shell ```shell
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### NGINX proxy with Go backend ### NGINX proxy with Go backend
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -21,6 +22,7 @@ Project structure:
``` ```
[`compose.yaml`](compose.yaml) [`compose.yaml`](compose.yaml)
``` ```
services: services:
proxy: proxy:
@ -40,6 +42,7 @@ services:
context: backend context: backend
target: builder target: builder
``` ```
The compose file defines an application with two services `proxy` and `backend`. The compose file defines an application with two services `proxy` and `backend`.
When deploying the application, docker compose maps port 80 of the frontend service container to the same port of the host as specified in the file. When deploying the application, docker compose maps port 80 of the frontend service container to the same port of the host as specified in the file.
Make sure port 80 on the host is not already in use. Make sure port 80 on the host is not already in use.
@ -47,7 +50,7 @@ Make sure port 80 on the host is not already in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "nginx-golang_default" with the default driver Creating network "nginx-golang_default" with the default driver
Building backend Building backend
Step 1/7 : FROM golang:1.13 AS build Step 1/7 : FROM golang:1.13 AS build
@ -62,14 +65,16 @@ Creating nginx-golang_proxy_1 ... done
## Expected result ## Expected result
Listing containers must show two containers running and the port mapping as below: Listing containers must show two containers running and the port mapping as below:
``` ```
$ docker compose ps $ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS NAME COMMAND SERVICE STATUS PORTS
nginx-golang-backend-1 "/code/bin/backend" backend running nginx-golang-backend-1 "/code/bin/backend" backend running
nginx-golang-proxy-1 "/docker-entrypoint.…" proxy running 0.0.0.0:80->80/tcp nginx-golang-proxy-1 "/docker-entrypoint.…" proxy running 0.0.0.0:80->80/tcp
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
``` ```
$ curl localhost:80 $ curl localhost:80
@ -87,6 +92,7 @@ Hello from Docker!
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -3,6 +3,7 @@
## Node.js application with Nginx proxy and Redis database ## Node.js application with Nginx proxy and Redis database
Project structure: Project structure:
``` ```
. .
├── README.md ├── README.md
@ -19,7 +20,9 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
redis: redis:
image: 'redislabs/redismod' image: 'redislabs/redismod'
@ -45,17 +48,17 @@ redis:
- web1 - web1
- web2 - web2
``` ```
The compose file defines an application with four services `redis`, `nginx`, `web1` and `web2`. The compose file defines an application with four services `redis`, `nginx`, `web1` and `web2`.
When deploying the application, docker compose maps port 80 of the nginx service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 80 of the nginx service container to port 80 of the host as specified in the file.
> **_INFO_** > **_INFO_**
> Redis runs on port 6379 by default. Make sure port 6379 on the host is not being used by another container, otherwise the port should be changed. > Redis runs on port 6379 by default. Make sure port 6379 on the host is not being used by another container, otherwise the port should be changed.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
[+] Running 24/24 [+] Running 24/24
⠿ redis Pulled ... ⠿ redis Pulled ...
⠿ 565225d89260 Pull complete ⠿ 565225d89260 Pull complete
@ -69,12 +72,10 @@ $ docker compose up -d
⠿ Container nginx-nodejs-redis-nginx-1 Started ⠿ Container nginx-nodejs-redis-nginx-1 Started
``` ```
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
``` ```
docker-compose ps docker-compose ps
``` ```
@ -93,16 +94,14 @@ web1: Total number of visits is: 1
curl localhost:80 curl localhost:80
web1: Total number of visits is: 2 web1: Total number of visits is: 2
``` ```
``` ```
$ curl localhost:80 $ curl localhost:80
web2: Total number of visits is: 3 web2: Total number of visits is: 3
``` ```
## Stop and remove the containers ## Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -40,7 +40,7 @@ Make sure port 80 on the host is not being used by another container, otherwise
## Deploy with docker compose ## Deploy with docker compose
```bash ```bash
$ docker compose up -d $ docker-compose up -d
Creating network "nginx-wsgi-flask_default" with the default driver Creating network "nginx-wsgi-flask_default" with the default driver
Building flask-app Building flask-app
... ...
@ -71,7 +71,7 @@ Hello World!
Stop and remove the containers Stop and remove the containers
```bash ```bash
$ docker compose down $ docker-compose down
Stopping nginx-wsgi-flask_nginx-proxy_1 ... done Stopping nginx-wsgi-flask_nginx-proxy_1 ... done
Stopping nginx-wsgi-flask_flask-app_1 ... done Stopping nginx-wsgi-flask_flask-app_1 ... done
Removing nginx-wsgi-flask_nginx-proxy_1 ... done Removing nginx-wsgi-flask_nginx-proxy_1 ... done
@ -99,6 +99,6 @@ Flask is a web development framework written in Python. It is the "backend" whic
A couple of sample endpoints are provided in this `docker-compose` example: A couple of sample endpoints are provided in this `docker-compose` example:
* `/` - Returns a "Hello World!" string. - `/` - Returns a "Hello World!" string.
* `/cache-me` - Returns a string which is cached by the NGINX reverse proxy. This demonstrates an intermediary cache implementation. - `/cache-me` - Returns a string which is cached by the NGINX reverse proxy. This demonstrates an intermediary cache implementation.
* `/info` - Returns informational headers about the request. Some are passed from NGINX for added client visibility. - `/info` - Returns informational headers about the request. Some are passed from NGINX for added client visibility.

View File

@ -79,7 +79,7 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
volumes: volumes:
- .:/code - .:/code
ports: ports:
- "8000:8000" - '8000:8000'
environment: environment:
- POSTGRES_NAME=postgres - POSTGRES_NAME=postgres
- POSTGRES_USER=postgres - POSTGRES_USER=postgres
@ -104,11 +104,11 @@ In this step, you create a Django starter project by building the image from the
1. Change to the root of your project directory. 1. Change to the root of your project directory.
2. Create the Django project by running the [docker compose run](https://docs.docker.com/engine/reference/commandline/compose_run/) 2. Create the Django project by running the [docker-compose run](https://docs.docker.com/engine/reference/commandline/compose_run/)
command as follows. command as follows.
```console ```console
sudo docker compose run web django-admin startproject composeexample . sudo docker-compose run web django-admin startproject composeexample .
``` ```
This instructs Compose to run `django-admin startproject composeexample` This instructs Compose to run `django-admin startproject composeexample`
@ -121,7 +121,7 @@ In this step, you create a Django starter project by building the image from the
instructs Django to create a set of files and directories representing a instructs Django to create a set of files and directories representing a
Django project. Django project.
3. After the `docker compose` command completes, list the contents of your project. 3. After the `docker-compose` command completes, list the contents of your project.
```console ```console
$ ls -l $ ls -l
@ -192,10 +192,10 @@ In this section, you set up the database connection for Django.
3. Save and close the file. 3. Save and close the file.
4. Run the [docker compose up](https://docs.docker.com/engine/reference/commandline/compose_up/) command from the top level directory for your project. 4. Run the [docker-compose up](https://docs.docker.com/engine/reference/commandline/compose_up/) command from the top level directory for your project.
```console ```console
$ docker compose up $ docker-compose up
djangosample_db_1 is up-to-date djangosample_db_1 is up-to-date
Creating djangosample_web_1 ... Creating djangosample_web_1 ...
@ -250,7 +250,7 @@ In this section, you set up the database connection for Django.
6. Shut down services and clean up by using either of these methods: 6. Shut down services and clean up by using either of these methods:
* Stop the application by typing `Ctrl-C` in the same shell in where you - Stop the application by typing `Ctrl-C` in the same shell in where you
started it: started it:
```console ```console
@ -259,12 +259,12 @@ In this section, you set up the database connection for Django.
Killing test_db_1 ... done Killing test_db_1 ... done
``` ```
* Or, for a more elegant shutdown, switch to a different shell, and run - Or, for a more elegant shutdown, switch to a different shell, and run
[docker compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) from the top level of your [docker-compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) from the top level of your
Django sample project directory. Django sample project directory.
```console ```console
$ docker compose down $ docker-compose down
Stopping django_web_1 ... done Stopping django_web_1 ... done
Stopping django_db_1 ... done Stopping django_db_1 ... done
@ -278,9 +278,9 @@ In this section, you set up the database connection for Django.
## More Compose documentation ## More Compose documentation
* [Docker Compose overview](https://docs.docker.com/compose/) - [Docker Compose overview](https://docs.docker.com/compose/)
* [Install Docker Compose](https://docs.docker.com/compose/install/) - [Install Docker Compose](https://docs.docker.com/compose/install/)
* [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/) - [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
* [Docker Compose Command line reference](https://docs.docker.com/compose/reference/) - [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
* [Compose file reference](https://docs.docker.com/compose/compose-file/) - [Compose file reference](https://docs.docker.com/compose/compose-file/)
* [Awesome Compose Django sample application](../../django/README.md) - [Awesome Compose Django sample application](../../django/README.md)

View File

@ -82,7 +82,7 @@ services:
volumes: volumes:
- .:/myapp - .:/myapp
ports: ports:
- "3000:3000" - '3000:3000'
depends_on: depends_on:
- db - db
``` ```
@ -94,10 +94,10 @@ services:
### Build the project ### Build the project
With those files in place, you can now generate the Rails skeleton app With those files in place, you can now generate the Rails skeleton app
using [docker compose run](https://docs.docker.com/engine/reference/commandline/compose_run/): using [docker-compose run](https://docs.docker.com/engine/reference/commandline/compose_run/):
```console ```console
$ docker compose run --no-deps web rails new . --force --database=postgresql $ docker-compose run --no-deps web rails new . --force --database=postgresql
``` ```
First, Compose builds the image for the `web` service using the `Dockerfile`. First, Compose builds the image for the `web` service using the `Dockerfile`.
@ -148,7 +148,7 @@ changes to the `Gemfile` or the Dockerfile, should be the only times youll ne
to rebuild.) to rebuild.)
```console ```console
$ docker compose build $ docker-compose build
``` ```
### Connect the database ### Connect the database
@ -173,17 +173,16 @@ development:
<<: *default <<: *default
database: myapp_development database: myapp_development
test: test:
<<: *default <<: *default
database: myapp_test database: myapp_test
``` ```
You can now boot the app with [docker compose up](https://docs.docker.com/engine/reference/commandline/compose_up/). You can now boot the app with [docker-compose up](https://docs.docker.com/engine/reference/commandline/compose_up/).
If all is well, you should see some PostgreSQL output: If all is well, you should see some PostgreSQL output:
```console ```console
$ docker compose up $ docker-compose up
rails_db_1 is up-to-date rails_db_1 is up-to-date
Creating rails_web_1 ... done Creating rails_web_1 ... done
@ -200,7 +199,7 @@ db_1 | 2018-03-21 20:18:37.772 UTC [1] LOG: database system is ready to accep
Finally, you need to create the database. In another terminal, run: Finally, you need to create the database. In another terminal, run:
```console ```console
$ docker compose run web rake db:create $ docker-compose run web rake db:create
Starting rails_db_1 ... done Starting rails_db_1 ... done
Created database 'myapp_development' Created database 'myapp_development'
Created database 'myapp_test' Created database 'myapp_test'
@ -217,13 +216,13 @@ browser to see the Rails Welcome.
### Stop the application ### Stop the application
To stop the application, run [docker compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) in To stop the application, run [docker-compose down](https://docs.docker.com/engine/reference/commandline/compose_down/) in
your project directory. You can use the same terminal window in which you your project directory. You can use the same terminal window in which you
started the database, or another one where you have access to a command prompt. started the database, or another one where you have access to a command prompt.
This is a clean way to stop the application. This is a clean way to stop the application.
```console ```console
$ docker compose down $ docker-compose down
Stopping rails_web_1 ... done Stopping rails_web_1 ... done
Stopping rails_db_1 ... done Stopping rails_db_1 ... done
@ -236,15 +235,15 @@ Removing network rails_default
### Restart the application ### Restart the application
To restart the application run `docker compose up` in the project directory. To restart the application run `docker-compose up` in the project directory.
### Rebuild the application ### Rebuild the application
If you make changes to the Gemfile or the Compose file to try out some different If you make changes to the Gemfile or the Compose file to try out some different
configurations, you need to rebuild. Some changes require only configurations, you need to rebuild. Some changes require only
`docker compose up --build`, but a full rebuild requires a re-run of `docker-compose up --build`, but a full rebuild requires a re-run of
`docker compose run web bundle install` to sync changes in the `Gemfile.lock` to `docker-compose run web bundle install` to sync changes in the `Gemfile.lock` to
the host, followed by `docker compose up --build`. the host, followed by `docker-compose up --build`.
Here is an example of the first case, where a full rebuild is not necessary. Here is an example of the first case, where a full rebuild is not necessary.
Suppose you simply want to change the exposed port on the local host from `3000` Suppose you simply want to change the exposed port on the local host from `3000`
@ -254,10 +253,10 @@ the changes:
```yaml ```yaml
ports: ports:
- "3001:3000" - '3001:3000'
``` ```
Now, rebuild and restart the app with `docker compose up --build`. Now, rebuild and restart the app with `docker-compose up --build`.
Inside the container, your app is running on the same port as before `3000`, but Inside the container, your app is running on the same port as before `3000`, but
the Rails Welcome is now available on `http://localhost:3001` on your local the Rails Welcome is now available on `http://localhost:3001` on your local
@ -265,8 +264,8 @@ host.
## More Compose documentation ## More Compose documentation
* [Docker Compose overview](https://docs.docker.com/compose/) - [Docker Compose overview](https://docs.docker.com/compose/)
* [Install Docker Compose](https://docs.docker.com/compose/install/) - [Install Docker Compose](https://docs.docker.com/compose/install/)
* [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/) - [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
* [Docker Compose Command line reference](https://docs.docker.com/compose/reference/) - [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
* [Compose file reference](https://docs.docker.com/compose/compose-file/) - [Compose file reference](https://docs.docker.com/compose/compose-file/)

View File

@ -17,7 +17,7 @@ Compose to set up and run WordPress. Before starting, make sure you have
is complete in itself for a good starter wordpress project. is complete in itself for a good starter wordpress project.
> **Tip**: You can use either a `.yml` or `.yaml` extension for > **Tip**: You can use either a `.yml` or `.yaml` extension for
this file. They both work. > this file. They both work.
2. Change into your project directory. 2. Change into your project directory.
@ -68,23 +68,23 @@ Compose to set up and run WordPress. Before starting, make sure you have
``` ```
> **Notes**: > **Notes**:
>
* The docker volumes `db_data` and `wordpress_data` persists updates made by WordPress - The docker volumes `db_data` and `wordpress_data` persists updates made by WordPress
to the database, as well as the installed themes and plugins. [Learn more about docker volumes](https://docs.docker.com/storage/volumes/) to the database, as well as the installed themes and plugins. [Learn more about docker volumes](https://docs.docker.com/storage/volumes/)
> >
* WordPress Multisite works only on ports `80` and `443`. - WordPress Multisite works only on ports `80` and `443`.
{: .note-vanilla} {: .note-vanilla}
### Build the project ### Build the project
Now, run `docker compose up -d` from your project directory. Now, run `docker-compose up -d` from your project directory.
This runs [`docker compose up`](https://docs.docker.com/engine/reference/commandline/compose_up/) in detached mode, pulls This runs [`docker-compose up`](https://docs.docker.com/engine/reference/commandline/compose_up/) in detached mode, pulls
the needed Docker images, and starts the wordpress and database containers, as shown in the needed Docker images, and starts the wordpress and database containers, as shown in
the example below. the example below.
```console ```console
$ docker compose up -d $ docker-compose up -d
Creating network "my_wordpress_default" with the default driver Creating network "my_wordpress_default" with the default driver
Pulling db (mysql:5.7)... Pulling db (mysql:5.7)...
@ -107,9 +107,9 @@ Creating my_wordpress_wordpress_1
``` ```
> **Note**: WordPress Multisite works only on ports `80` and/or `443`. > **Note**: WordPress Multisite works only on ports `80` and/or `443`.
If you get an error message about binding `0.0.0.0` to port `80` or `443` > If you get an error message about binding `0.0.0.0` to port `80` or `443`
(depending on which one you specified), it is likely that the port you > (depending on which one you specified), it is likely that the port you
configured for WordPress is already in use by another service. > configured for WordPress is already in use by another service.
### Bring up WordPress in a web browser ### Bring up WordPress in a web browser
@ -118,8 +118,8 @@ and you can complete the "famous five-minute installation" as a WordPress
administrator. administrator.
> **Note**: The WordPress site is not immediately available on port `80` > **Note**: The WordPress site is not immediately available on port `80`
because the containers are still being initialized and may take a couple of > because the containers are still being initialized and may take a couple of
minutes before the first load. > minutes before the first load.
If you are using Docker Desktop for Mac or Docker Desktop for Windows, you can use If you are using Docker Desktop for Mac or Docker Desktop for Windows, you can use
`http://localhost` as the IP address, and open `http://localhost:80` in a web `http://localhost` as the IP address, and open `http://localhost:80` in a web
@ -131,17 +131,17 @@ browser.
### Shutdown and cleanup ### Shutdown and cleanup
The command [`docker compose down`](https://docs.docker.com/engine/reference/commandline/compose_down/) removes the The command [`docker-compose down`](https://docs.docker.com/engine/reference/commandline/compose_down/) removes the
containers and default network, but preserves your WordPress database. containers and default network, but preserves your WordPress database.
The command `docker compose down --volumes` removes the containers, default The command `docker-compose down --volumes` removes the containers, default
network, and the WordPress database. network, and the WordPress database.
## More Compose documentation ## More Compose documentation
* [Docker Compose overview](https://docs.docker.com/compose/) - [Docker Compose overview](https://docs.docker.com/compose/)
* [Install Docker Compose](https://docs.docker.com/compose/install/) - [Install Docker Compose](https://docs.docker.com/compose/install/)
* [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/) - [Getting Started with Docker Compose](https://docs.docker.com/compose/gettingstarted/)
* [Docker Compose Command line reference](https://docs.docker.com/compose/reference/) - [Docker Compose Command line reference](https://docs.docker.com/compose/reference/)
* [Compose file reference](https://docs.docker.com/compose/compose-file/) - [Compose file reference](https://docs.docker.com/compose/compose-file/)
* [Awesome Compose WordPress sample](../../wordpress-mysql/README.md) - [Awesome Compose WordPress sample](../../wordpress-mysql/README.md)

View File

@ -1,9 +1,10 @@
## Pi-hole with cloudflared DoH (DNS-Over-HTTPS) ## Pi-hole with cloudflared DoH (DNS-Over-HTTPS)
This example provides a base setup for using [Pi-hole](https://docs.pi-hole.net/) with the [cloudflared DoH](https://docs.pi-hole.net/guides/dns/cloudflared/) service. This example provides a base setup for using [Pi-hole](https://docs.pi-hole.net/) with the [cloudflared DoH](https://docs.pi-hole.net/guides/dns/cloudflared/) service.
More details on how to customize the installation and the compose file can be found in [Docker Pi-hole documentation](https://github.com/pi-hole/docker-pi-hole). More details on how to customize the installation and the compose file can be found in [Docker Pi-hole documentation](https://github.com/pi-hole/docker-pi-hole).
Project structure: Project structure:
``` ```
. .
├── .env ├── .env
@ -12,6 +13,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```yaml ```yaml
services: services:
pihole: pihole:
@ -34,7 +36,9 @@ services:
## Configuration ## Configuration
### .env ### .env
Before deploying this setup, you need to configure the following values in the [.env](.env) file. Before deploying this setup, you need to configure the following values in the [.env](.env) file.
- TZ ([time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)) - TZ ([time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones))
- PIHOLE_PW (admin password) - PIHOLE_PW (admin password)
- PIHOLE_ROUTER_IP (only needed for activated conditional forwarding) - PIHOLE_ROUTER_IP (only needed for activated conditional forwarding)
@ -43,10 +47,13 @@ Before deploying this setup, you need to configure the following values in the [
- PIHOLE_HOST_IPV6 (IPv6 address of your Pi-hole - can be empty if you only use IPv4) - PIHOLE_HOST_IPV6 (IPv6 address of your Pi-hole - can be empty if you only use IPv4)
### Conditional forwarding (optional, default: enabled) ### Conditional forwarding (optional, default: enabled)
If you would like to disable conditional forwarding, delete the environment variables starting with "CONDITIONAL_FORWARDING" If you would like to disable conditional forwarding, delete the environment variables starting with "CONDITIONAL_FORWARDING"
### Container DNS (optional, default: disabled) ### Container DNS (optional, default: disabled)
In the docker compose file, dns is added as a comment. To enable dns remove '#' in front of the following lines: In the docker compose file, dns is added as a comment. To enable dns remove '#' in front of the following lines:
```yaml ```yaml
dns: dns:
- 127.0.0.1 # "Sets your container's resolve settings to localhost so it can resolve DHCP hostnames [...]" - github.com/pi-hole/docker-pi-hole - 127.0.0.1 # "Sets your container's resolve settings to localhost so it can resolve DHCP hostnames [...]" - github.com/pi-hole/docker-pi-hole
@ -54,18 +61,19 @@ dns:
``` ```
## Deploy with docker compose ## Deploy with docker compose
When deploying this setup, the admin web interface will be available on port 8080 (e.g. http://localhost:8080/admin). When deploying this setup, the admin web interface will be available on port 8080 (e.g. http://localhost:8080/admin).
```shell ```shell
$ docker compose up -d $ docker-compose up -d
Starting cloudflared ... done Starting cloudflared ... done
Starting pihole ... done Starting pihole ... done
``` ```
## Expected result ## Expected result
Check containers are running and the port mapping: Check containers are running and the port mapping:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -75,34 +83,40 @@ dfd49ab7a372 visibilityspots/cloudflared "/bin/sh -c '/usr/lo…"
Navigate to `http://localhost:8080` in your web browser to access the installed Pi-hole web interface. Navigate to `http://localhost:8080` in your web browser to access the installed Pi-hole web interface.
Stop the containers with Stop the containers with
```shell ```shell
$ docker compose down $ docker-compose down
# To delete all data run: # To delete all data run:
$ docker compose down -v $ docker-compose down -v
``` ```
## Troubleshooting ## Troubleshooting
### - Starting / Stopping pihole-FTL loop: ### - Starting / Stopping pihole-FTL loop:
Sometimes, it can happen that there occurs a problem starting pihole-FTL. Sometimes, it can happen that there occurs a problem starting pihole-FTL.
I personally had this issue when adding this line to the shared volumes: I personally had this issue when adding this line to the shared volumes:
``` ```
- "/pihole/pihole.log:/var/log/pihole.log" - "/pihole/pihole.log:/var/log/pihole.log"
``` ```
To fix this issue, I found this [issue](https://github.com/pi-hole/docker-pi-hole/issues/645#issuecomment-670809672), To fix this issue, I found this [issue](https://github.com/pi-hole/docker-pi-hole/issues/645#issuecomment-670809672),
which suggested adding an empty file (`touch /pihole/pihole.log`) to prevent it from creating a directory. which suggested adding an empty file (`touch /pihole/pihole.log`) to prevent it from creating a directory.
The directory would not allow starting pihole-FTL and result in something like this: The directory would not allow starting pihole-FTL and result in something like this:
``` ```
# Starting pihole-FTL (no-daemon) as root # Starting pihole-FTL (no-daemon) as root
# Stopping pihole-FTL # Stopping pihole-FTL
... ...
``` ```
If you created an empty file, you may also check the ownership to prevent permission problems. If you created an empty file, you may also check the ownership to prevent permission problems.
### - Installing on Ubuntu may conflict with `systemd-resolved` - see [Installing on Ubuntu](https://github.com/pi-hole/docker-pi-hole#installing-on-ubuntu-or-fedora) for help. ### - Installing on Ubuntu may conflict with `systemd-resolved` - see [Installing on Ubuntu](https://github.com/pi-hole/docker-pi-hole#installing-on-ubuntu-or-fedora) for help.
### - Environment variables are version-dependent ### - Environment variables are version-dependent
Environment variables like "CONDIIONAL_FORWARDING*" and "DNS1" are deprecated and replaced by e.g. "REV_SERVER*" and "PIHOLE_DNS" in version 5.8+. Environment variables like "CONDIIONAL_FORWARDING*" and "DNS1" are deprecated and replaced by e.g. "REV_SERVER*" and "PIHOLE_DNS" in version 5.8+.
Current information about environment variables can be found here: https://github.com/pi-hole/docker-pi-hole Current information about environment variables can be found here: https://github.com/pi-hole/docker-pi-hole

View File

@ -1,10 +1,11 @@
## Plex ## Plex
This example provides a base setup for using [Plex](https://www.plex.tv/). This example provides a base setup for using [Plex](https://www.plex.tv/).
More details on how to customize the installation and the compose file can be found in [linuxserver documentation](https://github.com/linuxserver/docker-plex). More details on how to customize the installation and the compose file can be found in [linuxserver documentation](https://github.com/linuxserver/docker-plex).
Alternatively, you can use different plex images (e.g. official plex image by [plexinc](https://github.com/plexinc/pms-docker)) Alternatively, you can use different plex images (e.g. official plex image by [plexinc](https://github.com/plexinc/pms-docker))
Project structure: Project structure:
``` ```
. .
├── .env ├── .env
@ -13,6 +14,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```yaml ```yaml
services: services:
plex: plex:
@ -22,24 +24,28 @@ services:
## Configuration ## Configuration
### .env ### .env
Before deploying this setup, you need to configure the following values in the [.env](.env) file. Before deploying this setup, you need to configure the following values in the [.env](.env) file.
- PLEX_MEDIA_PATH - PLEX_MEDIA_PATH
### Hardware Acceleration ### Hardware Acceleration
Check out the description for Hardware Acceleration support in the [documentation](https://github.com/linuxserver/docker-plex). Check out the description for Hardware Acceleration support in the [documentation](https://github.com/linuxserver/docker-plex).
## Deploy with docker compose ## Deploy with docker compose
When deploying this setup, the web interface will be available on port 32400 (e.g. http://localhost:32400/web). When deploying this setup, the web interface will be available on port 32400 (e.g. http://localhost:32400/web).
```shell ```shell
$ docker compose up -d $ docker-compose up -d
Starting plex ... done Starting plex ... done
``` ```
## Expected result ## Expected result
Check containers are running: Check containers are running:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -48,10 +54,10 @@ CONTAINER ID IMAGE COMMAND CREATE
Navigate to `http://localhost:32400/web` in your web browser to access the plex web interface. Navigate to `http://localhost:32400/web` in your web browser to access the plex web interface.
Stop the containers with Stop the containers with
```shell ```shell
$ docker compose down $ docker-compose down
# To delete all data run: # To delete all data run:
$ docker compose down -v $ docker-compose down -v
``` ```

View File

@ -1,13 +1,17 @@
## Portainer (CE) ## Portainer (CE)
This example provides a base setup for using [Portainer](https://www.portainer.io/). This example provides a base setup for using [Portainer](https://www.portainer.io/).
More details on how to customize the installation and the compose file can be found in [portainer documentation](https://documentation.portainer.io/). More details on how to customize the installation and the compose file can be found in [portainer documentation](https://documentation.portainer.io/).
### Demo ### Demo
You can try out the public demo instance first: http://demo.portainer.io/ You can try out the public demo instance first: http://demo.portainer.io/
- username: admin - username: admin
- password: tryportainer - password: tryportainer
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -15,6 +19,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```yaml ```yaml
services: services:
portainer: portainer:
@ -22,17 +27,18 @@ services:
``` ```
## Deploy with docker compose ## Deploy with docker compose
When deploying this setup, the web interface will be available on port 9000 (e.g. http://localhost:9000). When deploying this setup, the web interface will be available on port 9000 (e.g. http://localhost:9000).
```shell ```shell
$ docker compose up -d $ docker-compose up -d
Starting portainer ... done Starting portainer ... done
``` ```
## Expected result ## Expected result
Check containers are running: Check containers are running:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -42,15 +48,16 @@ CONTAINER ID IMAGE COMMAND CREATED
Navigate to `http://localhost:9000` in your web browser to access the portainer web interface and create an account. Navigate to `http://localhost:9000` in your web browser to access the portainer web interface and create an account.
Stop the containers with Stop the containers with
```shell ```shell
$ docker compose down $ docker-compose down
# To delete all data run: # To delete all data run:
$ docker compose down -v $ docker-compose down -v
``` ```
## Troubleshooting ## Troubleshooting
- Select the correct image for your OS. You can take a look at the published tags at [DockerHub](https://hub.docker.com/r/portainer/portainer-ce/tags) - Select the correct image for your OS. You can take a look at the published tags at [DockerHub](https://hub.docker.com/r/portainer/portainer-ce/tags)
> e.g. currently, the latest tag is for Windows (amd64) and alpine for Linux (amd64, arm/v7) > e.g. currently, the latest tag is for Windows (amd64) and alpine for Linux (amd64, arm/v7)

View File

@ -1,8 +1,10 @@
## PostgreSQL and pgAdmin ## PostgreSQL and pgAdmin
This example provides a base setup for using [PostgreSQL](https://www.postgresql.org/) and [pgAdmin](https://www.pgadmin.org/). This example provides a base setup for using [PostgreSQL](https://www.postgresql.org/) and [pgAdmin](https://www.pgadmin.org/).
More details on how to customize the installation and the compose file can be found [here (PostgreSQL)](https://hub.docker.com/_/postgres) and [here (pgAdmin)](https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html). More details on how to customize the installation and the compose file can be found [here (PostgreSQL)](https://hub.docker.com/_/postgres) and [here (pgAdmin)](https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html).
Project structure: Project structure:
``` ```
. .
├── .env ├── .env
@ -11,6 +13,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```yaml ```yaml
services: services:
postgres: postgres:
@ -23,7 +26,9 @@ services:
## Configuration ## Configuration
### .env ### .env
Before deploying this setup, you need to configure the following values in the [.env](.env) file. Before deploying this setup, you need to configure the following values in the [.env](.env) file.
- POSTGRES_USER - POSTGRES_USER
- POSTGRES_PW - POSTGRES_PW
- POSTGRES_DB (can be default value) - POSTGRES_DB (can be default value)
@ -31,19 +36,23 @@ Before deploying this setup, you need to configure the following values in the [
- PGADMIN_PW - PGADMIN_PW
## Deploy with docker compose ## Deploy with docker compose
When deploying this setup, the pgAdmin web interface will be available at port 5050 (e.g. http://localhost:5050). When deploying this setup, the pgAdmin web interface will be available at port 5050 (e.g. http://localhost:5050).
```shell ```shell
$ docker compose up $ docker-compose up
Starting postgres ... done Starting postgres ... done
Starting pgadmin ... done Starting pgadmin ... done
``` ```
## Add postgres database to pgAdmin ## Add postgres database to pgAdmin
After logging in with your credentials of the .env file, you can add your database to pgAdmin. After logging in with your credentials of the .env file, you can add your database to pgAdmin.
1. Right-click "Servers" in the top-left corner and select "Create" -> "Server..." 1. Right-click "Servers" in the top-left corner and select "Create" -> "Server..."
2. Name your connection 2. Name your connection
3. Change to the "Connection" tab and add the connection details: 3. Change to the "Connection" tab and add the connection details:
- Hostname: "postgres" (this would normally be your IP address of the postgres database - however, docker can resolve this container ip by its name) - Hostname: "postgres" (this would normally be your IP address of the postgres database - however, docker can resolve this container ip by its name)
- Port: "5432" - Port: "5432"
- Maintenance Database: $POSTGRES_DB (see .env) - Maintenance Database: $POSTGRES_DB (see .env)
@ -53,6 +62,7 @@ After logging in with your credentials of the .env file, you can add your databa
## Expected result ## Expected result
Check containers are running: Check containers are running:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -61,8 +71,9 @@ d3cde3b455ee dpage/pgadmin4:latest "/entrypoint.sh" 9 minute
``` ```
Stop the containers with Stop the containers with
```shell ```shell
$ docker compose down $ docker-compose down
# To delete all data run: # To delete all data run:
$ docker compose down -v $ docker-compose down -v
``` ```

View File

@ -1,7 +1,9 @@
## Compose sample ## Compose sample
### Prometheus & Grafana ### Prometheus & Grafana
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -13,6 +15,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
prometheus: prometheus:
@ -26,6 +29,7 @@ services:
ports: ports:
- 3000:3000 - 3000:3000
``` ```
The compose file defines a stack with two services `prometheus` and `grafana`. The compose file defines a stack with two services `prometheus` and `grafana`.
When deploying the stack, docker compose maps port the default ports for each service to the equivalent ports on the host in order to inspect easier the web interface of each service. When deploying the stack, docker compose maps port the default ports for each service to the equivalent ports on the host in order to inspect easier the web interface of each service.
Make sure the ports 9090 and 3000 on the host are not already in use. Make sure the ports 9090 and 3000 on the host are not already in use.
@ -33,7 +37,7 @@ Make sure the ports 9090 and 3000 on the host are not already in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "prometheus-grafana_default" with the default driver Creating network "prometheus-grafana_default" with the default driver
Creating volume "prometheus-grafana_prom_data" with default driver Creating volume "prometheus-grafana_prom_data" with default driver
... ...
@ -46,6 +50,7 @@ Attaching to prometheus, grafana
## Expected result ## Expected result
Listing containers must show two containers running and the port mapping as below: Listing containers must show two containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -60,6 +65,7 @@ Navigate to `http://localhost:3000` in your web browser and use the login creden
Navigate to `http://localhost:9090` in your web browser to access directly the web interface of prometheus. Navigate to `http://localhost:9090` in your web browser to access directly the web interface of prometheus.
Stop and remove the containers. Use `-v` to remove the volumes if looking to erase all data. Stop and remove the containers. Use `-v` to remove the volumes if looking to erase all data.
``` ```
$ docker compose down -v $ docker-compose down -v
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### React application with a NodeJS backend and a MongoDB database ### React application with a NodeJS backend and a MongoDB database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -22,6 +23,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
frontend: frontend:
@ -48,6 +50,7 @@ services:
restart: always restart: always
... ...
``` ```
The compose file defines an application with three services `frontend`, `backend` and `db`. The compose file defines an application with three services `frontend`, `backend` and `db`.
When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file. When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file.
Make sure port 3000 on the host is not already being in use. Make sure port 3000 on the host is not already being in use.
@ -55,7 +58,7 @@ Make sure port 3000 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "react-express-mongodb_default" with the default driver Creating network "react-express-mongodb_default" with the default driver
Building frontend Building frontend
Step 1/9 : FROM node:13.13.0-stretch-slim Step 1/9 : FROM node:13.13.0-stretch-slim
@ -71,6 +74,7 @@ Creating app ... done
## Expected result ## Expected result
Listing containers must show containers running and the port mapping as below: Listing containers must show containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -84,8 +88,9 @@ After the application starts, navigate to `http://localhost:3000` in your web br
![page](./output.png) ![page](./output.png)
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping server ... done Stopping server ... done
Stopping frontend ... done Stopping frontend ... done
Stopping mongo ... done Stopping mongo ... done
@ -96,39 +101,40 @@ Removing mongo ... done
##### Explanation of `docker-compose` ##### Explanation of `docker-compose`
__Version__ **Version**
The first line defines the version of a file. It sounds confusing :confused:. What is meant by version of file ?? The first line defines the version of a file. It sounds confusing :confused:. What is meant by version of file ??
:pill: The Compose file is a YAML file defining services, networks, and volumes for a Docker application. So it is only a version of describing compose.yaml file. There are several versions of the Compose file format 1, 2, 2.x, and 3.x. :pill: The Compose file is a YAML file defining services, networks, and volumes for a Docker application. So it is only a version of describing compose.yaml file. There are several versions of the Compose file format 1, 2, 2.x, and 3.x.
__Services__ **Services**
Our main goal to create a containers, it starts from here. As you can see there are three services(Docker images): Our main goal to create a containers, it starts from here. As you can see there are three services(Docker images):
- First is __frontend__
- Second is __server__ which is __backend - Express(NodeJS)__. I used a name server here, it's totally on you to name it __backend__. - First is **frontend**
- Third is __mongo__ which is db __MongoDB__. - Second is **server** which is **backend - Express(NodeJS)**. I used a name server here, it's totally on you to name it **backend**.
- Third is **mongo** which is db **MongoDB**.
##### Service app (backend - NodeJS) ##### Service app (backend - NodeJS)
We make image of app from our `Dockerfile`, explanation below. We make image of app from our `Dockerfile`, explanation below.
__Explanation of service server__ **Explanation of service server**
- Defining a **nodejs** service as __server__. - Defining a **nodejs** service as **server**.
- We named our **node server** container service as **server**. Assigning a name to the containers makes it easier to read when there are lot of containers on a machine, it can also avoid randomly generated container names. (Although in this case, __container_name__ is also __server__, this is merely personal preference, the name of the service and container do not have to be the same.) - We named our **node server** container service as **server**. Assigning a name to the containers makes it easier to read when there are lot of containers on a machine, it can also avoid randomly generated container names. (Although in this case, **container_name** is also **server**, this is merely personal preference, the name of the service and container do not have to be the same.)
- Docker container starts automatically if its fails. - Docker container starts automatically if its fails.
- Building the __server__ image using the Dockerfile from the current directory and passing an argument to the - Building the **server** image using the Dockerfile from the current directory and passing an argument to the
backend(server) `DockerFile`. backend(server) `DockerFile`.
- Mapping the host port to the container port. - Mapping the host port to the container port.
##### Service mongo ##### Service mongo
We add another service called **mongo** but this time instead of building it from `DockerFile` we write all the instruction here directly. We simply pull down the standard __mongo image__ from the [DockerHub](https://hub.docker.com/) registry as we have done it for Node image. We add another service called **mongo** but this time instead of building it from `DockerFile` we write all the instruction here directly. We simply pull down the standard **mongo image** from the [DockerHub](https://hub.docker.com/) registry as we have done it for Node image.
__Explanation of service mongo__ **Explanation of service mongo**
- Defining a **mongodb** service as __mongo__. - Defining a **mongodb** service as **mongo**.
- Pulling the mongo 4.2.0 image image again from [DockerHub](https://hub.docker.com/). - Pulling the mongo 4.2.0 image image again from [DockerHub](https://hub.docker.com/).
- Mount our current db directory to container. - Mount our current db directory to container.
- For persistent storage, we mount the host directory ( just like I did it in **Node** image inside `DockerFile` to reflect the changes) `/data` ( you need to create a directory in root of your project in order to save changes to locally as well) to the container directory `/data/db`, which was identified as a potential mount point in the `mongo Dockerfile` we saw earlier. - For persistent storage, we mount the host directory ( just like I did it in **Node** image inside `DockerFile` to reflect the changes) `/data` ( you need to create a directory in root of your project in order to save changes to locally as well) to the container directory `/data/db`, which was identified as a potential mount point in the `mongo Dockerfile` we saw earlier.
@ -138,4 +144,4 @@ __Explanation of service mongo__
:key: `If you wish to check your DB changes on your local machine as well. You should have installed MongoDB locally, otherwise you can't access your mongodb service of container from host machine.` :key: `If you wish to check your DB changes on your local machine as well. You should have installed MongoDB locally, otherwise you can't access your mongodb service of container from host machine.`
:white_check_mark: You should check your __mongo__ version is same as used in image. You can see the version of __mongo__ image in `docker-compose `file, I used __image: mongo:4.2.0__. If your mongo db version on your machine is not same then furst you have to updated your local __mongo__ version in order to works correctly. :white_check_mark: You should check your **mongo** version is same as used in image. You can see the version of **mongo** image in `docker-compose `file, I used **image: mongo:4.2.0**. If your mongo db version on your machine is not same then furst you have to updated your local **mongo** version in order to works correctly.

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### React application with a NodeJS backend and a MySQL database ### React application with a NodeJS backend and a MySQL database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -24,6 +25,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -45,6 +47,7 @@ services:
- 3000:3000 - 3000:3000
... ...
``` ```
The compose file defines an application with three services `frontend`, `backend` and `db`. The compose file defines an application with three services `frontend`, `backend` and `db`.
When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file. When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file.
Make sure port 3000 on the host is not already being in use. Make sure port 3000 on the host is not already being in use.
@ -57,7 +60,7 @@ Make sure port 3000 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "react-express-mysql_default" with the default driver Creating network "react-express-mysql_default" with the default driver
Building backend Building backend
Step 1/16 : FROM node:10 Step 1/16 : FROM node:10
@ -73,6 +76,7 @@ Creating react-express-mysql_frontend_1 ... done
## Expected result ## Expected result
Listing containers must show containers running and the port mapping as below: Listing containers must show containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -85,16 +89,17 @@ After the application starts, navigate to `http://localhost:3000` in your web br
![page](./output.png) ![page](./output.png)
The backend service container has the port 80 mapped to 80 on the host. The backend service container has the port 80 mapped to 80 on the host.
``` ```
$ curl localhost:80 $ curl localhost:80
{"message":"Hello from MySQL 8.0.19"} {"message":"Hello from MySQL 8.0.19"}
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping react-express-mysql_frontend_1 ... done Stopping react-express-mysql_frontend_1 ... done
Stopping react-express-mysql_backend_1 ... done Stopping react-express-mysql_backend_1 ... done
Stopping react-express-mysql_db_1 ... done Stopping react-express-mysql_db_1 ... done

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### React application with a Spring backend and a MySQL database ### React application with a Spring backend and a MySQL database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -24,6 +25,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -41,6 +43,7 @@ services:
- 3000:3000 - 3000:3000
... ...
``` ```
The compose file defines an application with three services `frontend`, `backend` and `db`. The compose file defines an application with three services `frontend`, `backend` and `db`.
When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file. When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file.
Make sure port 3000 on the host is not already being in use. Make sure port 3000 on the host is not already being in use.
@ -53,7 +56,7 @@ Make sure port 3000 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "react-java-mysql-default" with the default driver Creating network "react-java-mysql-default" with the default driver
Building backend Building backend
Step 1/17 : FROM maven:3.6.3-jdk-11 AS builder Step 1/17 : FROM maven:3.6.3-jdk-11 AS builder
@ -68,6 +71,7 @@ Creating react-java-mysql-backend-1 ... done
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
ONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -80,8 +84,9 @@ After the application starts, navigate to `http://localhost:3000` in your web br
![page](./output.jpg) ![page](./output.jpg)
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping react-java-mysql-backend-1 ... done Stopping react-java-mysql-backend-1 ... done
Stopping react-java-mysql-frontend-1 ... done Stopping react-java-mysql-frontend-1 ... done
Stopping react-java-mysql-db-1 ... done Stopping react-java-mysql-db-1 ... done

View File

@ -46,7 +46,7 @@ When deploying the application, docker compose maps port 80 of the frontend serv
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Building frontend Building frontend
Sending build context to Docker daemon 1.49MB Sending build context to Docker daemon 1.49MB
@ -87,7 +87,7 @@ After the application start, navigate to http://localhost in your browser:
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping frontend ... done Stopping frontend ... done
Removing frontend ... done Removing frontend ... done
Removing network react-nginx_default Removing network react-nginx_default

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### React application with a Rust backend and a Postgresql database ### React application with a Rust backend and a Postgresql database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -22,6 +23,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -36,6 +38,7 @@ services:
- 3000:3000 - 3000:3000
... ...
``` ```
The compose file defines an application with three services `frontend`, `backend` and `db`. The compose file defines an application with three services `frontend`, `backend` and `db`.
When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file. When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host as specified in the file.
Make sure port 3000 on the host is not already being in use. Make sure port 3000 on the host is not already being in use.
@ -43,7 +46,7 @@ Make sure port 3000 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "react-rust-postgres_default" with the default driver Creating network "react-rust-postgres_default" with the default driver
Building backend Building backend
... ...
@ -57,6 +60,7 @@ Creating react-rust-postgres_backend_1 ... done
## Expected result ## Expected result
Listing containers must show three containers running and the port mapping as below: Listing containers must show three containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -70,8 +74,9 @@ After the application starts, navigate to `http://localhost:3000` in your web br
![page](./capture.png) ![page](./capture.png)
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping react-rust-postgres_backend_1 ... done Stopping react-rust-postgres_backend_1 ... done
Stopping react-rust-postgres_frontend_1 ... done Stopping react-rust-postgres_frontend_1 ... done
Stopping react-rust-postgres_db_1 ... done Stopping react-rust-postgres_db_1 ... done

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Java Spark application with MySQL database ### Java Spark application with MySQL database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -22,6 +23,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -35,6 +37,7 @@ services:
#image: mysql:8.0.27 #image: mysql:8.0.27
... ...
``` ```
The compose file defines an application with two services `backend` and `db`. The compose file defines an application with two services `backend` and `db`.
When deploying the application, docker compose maps port 8080 of the backend service container to port 80 of the host as specified in the file. When deploying the application, docker compose maps port 8080 of the backend service container to port 80 of the host as specified in the file.
Make sure port 8080 on the host is not already being in use. Make sure port 8080 on the host is not already being in use.
@ -47,7 +50,7 @@ Make sure port 8080 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "sparkjava-mysql_default" with the default driver Creating network "sparkjava-mysql_default" with the default driver
Building backend Building backend
... ...
@ -60,6 +63,7 @@ Creating sparkjava-mysql_backend_1 ... done
## Expected result ## Expected result
Listing containers must show two containers running and the port mapping as below: Listing containers must show two containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -68,14 +72,16 @@ ee1e4f05d9f6 sparkjava-mysql_backend "/bin/sh -c 'java -j…" 44 seco
``` ```
After the application starts, run: After the application starts, run:
``` ```
$ curl localhost:8080 $ curl localhost:8080
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"] ["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping sparkjava-mysql_backend_1 ... done Stopping sparkjava-mysql_backend_1 ... done
Stopping sparkjava-mysql_db_1 ... done Stopping sparkjava-mysql_db_1 ... done
Removing sparkjava-mysql_backend_1 ... done Removing sparkjava-mysql_backend_1 ... done

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Spark Java ### Spark Java
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -19,6 +20,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
sparkjava: sparkjava:
@ -26,6 +28,7 @@ services:
ports: ports:
- 8080:8080 - 8080:8080
``` ```
The compose file defines an application with one service `sparkjava`. The compose file defines an application with one service `sparkjava`.
When deploying the application, docker compose maps port 8080 of the sparkjava service container to port 8080 of the host as specified in the file. When deploying the application, docker compose maps port 8080 of the sparkjava service container to port 8080 of the host as specified in the file.
Make sure port 8080 on the host is not already being in use. Make sure port 8080 on the host is not already being in use.
@ -33,7 +36,7 @@ Make sure port 8080 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "sparkjava_default" with the default driver Creating network "sparkjava_default" with the default driver
Building sparkjava Building sparkjava
Step 1/11 : FROM maven:3.6.3-jdk-11 AS build Step 1/11 : FROM maven:3.6.3-jdk-11 AS build
@ -47,6 +50,7 @@ Creating sparkjava_sparkjava_1 ... done
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -54,14 +58,16 @@ CONTAINER ID IMAGE COMMAND CREATED
``` ```
After the application starts, navigate to `http://localhost:8080` in your web browser or run: After the application starts, navigate to `http://localhost:8080` in your web browser or run:
``` ```
$ curl localhost:8080 $ curl localhost:8080
Hello from Docker! Hello from Docker!
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping sparkjava_sparkjava_1 ... done Stopping sparkjava_sparkjava_1 ... done
Removing sparkjava_sparkjava_1 ... done Removing sparkjava_sparkjava_1 ... done
Removing network sparkjava_default Removing network sparkjava_default

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### Java application with Spring framework and a Postgres database ### Java application with Spring framework and a Postgres database
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -22,6 +23,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
backend: backend:
@ -32,6 +34,7 @@ services:
image: postgres image: postgres
... ...
``` ```
The compose file defines an application with two services `backend` and `db`. The compose file defines an application with two services `backend` and `db`.
When deploying the application, docker compose maps port 8080 of the backend service container to port 8080 of the host as specified in the file. When deploying the application, docker compose maps port 8080 of the backend service container to port 8080 of the host as specified in the file.
Make sure port 8080 on the host is not already being in use. Make sure port 8080 on the host is not already being in use.
@ -39,7 +42,7 @@ Make sure port 8080 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "spring-postgres_default" with the default driver Creating network "spring-postgres_default" with the default driver
Building backend Building backend
Step 1/11 : FROM maven:3.5-jdk-9 AS build Step 1/11 : FROM maven:3.5-jdk-9 AS build
@ -54,6 +57,7 @@ Creating spring-postgres_db_1 ... done
## Expected result ## Expected result
Listing containers must show two containers running and the port mapping as below: Listing containers must show two containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -62,6 +66,7 @@ CONTAINER ID IMAGE COMMAND CREATED
``` ```
After the application starts, navigate to `http://localhost:8080` in your web browse or run: After the application starts, navigate to `http://localhost:8080` in your web browse or run:
``` ```
$ curl localhost:8080 $ curl localhost:8080
<!DOCTYPE HTML> <!DOCTYPE HTML>
@ -76,8 +81,9 @@ $ curl localhost:8080
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping spring-postgres_db_1 ... done Stopping spring-postgres_db_1 ... done
Stopping spring-postgres_backend_1 ... done Stopping spring-postgres_backend_1 ... done
Removing spring-postgres_db_1 ... done Removing spring-postgres_db_1 ... done

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### TRAEFIK proxy with GO backend ### TRAEFIK proxy with GO backend
Project structure: Project structure:
``` ```
. .
├── backend ├── backend
@ -19,6 +20,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
frontend: frontend:
@ -40,6 +42,7 @@ services:
- "traefik.http.services.go.loadbalancer.server.port=80" - "traefik.http.services.go.loadbalancer.server.port=80"
``` ```
The compose file defines an application with two services `frontend` and `backend`. The compose file defines an application with two services `frontend` and `backend`.
When deploying the application, docker compose maps port 80 of the frontend service container to the same port of the host as specified in the file. When deploying the application, docker compose maps port 80 of the frontend service container to the same port of the host as specified in the file.
Make sure port 80 on the host is not already being in use. Make sure port 80 on the host is not already being in use.
@ -47,7 +50,7 @@ Make sure port 80 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "traefik-golang_default" with the default driver Creating network "traefik-golang_default" with the default driver
Building backend Building backend
Step 1/7 : FROM golang:1.13 AS build Step 1/7 : FROM golang:1.13 AS build
@ -71,6 +74,7 @@ Creating traefik-golang_frontend_1 ... done
## Expected result ## Expected result
Listing containers must show two containers running and the port mapping as below: Listing containers must show two containers running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -79,6 +83,7 @@ e0a0f3191042 traefik:2.6 "/entrypoint.sh --pr…" 42 seconds ag
``` ```
After the application starts, navigate to `http://localhost:80` in your web browser or run: After the application starts, navigate to `http://localhost:80` in your web browser or run:
``` ```
$ curl localhost:80 $ curl localhost:80
@ -96,6 +101,7 @@ Hello from Docker!
``` ```
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
``` ```

View File

@ -9,6 +9,7 @@ You can open this sample in the Dev Environments feature of Docker Desktop versi
### VueJS ### VueJS
Project structure: Project structure:
``` ```
. .
├── compose.yaml ├── compose.yaml
@ -19,6 +20,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
``` ```
services: services:
web: web:
@ -29,6 +31,7 @@ services:
- ./vuejs:/project - ./vuejs:/project
- /project/node_modules - /project/node_modules
``` ```
The compose file defines an application with one service `vuejs`. The compose file defines an application with one service `vuejs`.
When deploying the application, docker compose maps port 8080 of the web service container to port 8080 of the host as specified in the file. When deploying the application, docker compose maps port 8080 of the web service container to port 8080 of the host as specified in the file.
Make sure port 8080 on the host is not already being in use. Make sure port 8080 on the host is not already being in use.
@ -36,7 +39,7 @@ Make sure port 8080 on the host is not already being in use.
## Deploy with docker compose ## Deploy with docker compose
``` ```
$ docker compose up -d $ docker-compose up -d
Creating network "vuejs_default" with the default driver Creating network "vuejs_default" with the default driver
Building web Building web
Step 1/8 : FROM node:13.10.1-alpine Step 1/8 : FROM node:13.10.1-alpine
@ -49,6 +52,7 @@ Creating vuejs_web_1 ... done
## Expected result ## Expected result
Listing containers must show one container running and the port mapping as below: Listing containers must show one container running and the port mapping as below:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -60,8 +64,9 @@ After the application starts, navigate to `http://localhost:80` in your web brow
![page](output.jpg) ![page](output.jpg)
Stop and remove the containers Stop and remove the containers
``` ```
$ docker compose down $ docker-compose down
Stopping vuejs_web_1 ... done Stopping vuejs_web_1 ... done
Removing vuejs_web_1 ... done Removing vuejs_web_1 ... done
Removing network vuejs_default Removing network vuejs_default

View File

@ -1,8 +1,10 @@
## Wireguard ## Wireguard
This example provides a base setup for using [Wireguard](https://www.wireguard.com/). This example provides a base setup for using [Wireguard](https://www.wireguard.com/).
More details on how to customize the installation and the compose file can be found in [linuxserver documentation](https://hub.docker.com/r/linuxserver/wireguard). More details on how to customize the installation and the compose file can be found in [linuxserver documentation](https://hub.docker.com/r/linuxserver/wireguard).
Project structure: Project structure:
``` ```
. .
├── .env ├── .env
@ -11,6 +13,7 @@ Project structure:
``` ```
[_compose.yaml_](compose.yaml) [_compose.yaml_](compose.yaml)
```yaml ```yaml
services: services:
wireguard: wireguard:
@ -20,15 +23,18 @@ services:
## Configuration ## Configuration
### .env ### .env
Before deploying this setup, you need to configure the following values in the [.env](.env) file. Before deploying this setup, you need to configure the following values in the [.env](.env) file.
- TIMEZONE - TIMEZONE
- VPN_SERVER_URL (recommended setting up a server url with e.g. http://www.duckdns.org/ if you don't own a domain) - VPN_SERVER_URL (recommended setting up a server url with e.g. http://www.duckdns.org/ if you don't own a domain)
## Deploy with docker compose ## Deploy with docker compose
When deploying this setup, the log will show relevant information. You need to forward the external port 51820 to access your VPN from outside. When deploying this setup, the log will show relevant information. You need to forward the external port 51820 to access your VPN from outside.
```shell ```shell
$ docker compose up $ docker-compose up
Starting wireguard ... Starting wireguard ...
wireguard | **** It seems the wireguard module is already active. Skipping kernel header install and module compilation. **** wireguard | **** It seems the wireguard module is already active. Skipping kernel header install and module compilation. ****
wireguard | **** Server mode is selected **** wireguard | **** Server mode is selected ****
@ -43,6 +49,7 @@ wireguard | [GENERATED QR CODE TO SCAN FOR YOUR CONNECTION DETAILS]
## Expected result ## Expected result
Check containers are running: Check containers are running:
``` ```
$ docker ps $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
@ -52,27 +59,32 @@ CONTAINER ID IMAGE COMMAND CREATED
## Mobile Wireguard App ## Mobile Wireguard App
### Android ### Android
<a href="https://play.google.com/store/apps/details?id=com.wireguard.android"><img src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png" height="75"></a> <a href="https://play.google.com/store/apps/details?id=com.wireguard.android"><img src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png" height="75"></a>
Install your Wireguard client on an Apple device by downloading the wireguard app and scanning the QR Code. Install your Wireguard client on an Apple device by downloading the wireguard app and scanning the QR Code.
### iOS ### iOS
<a href="https://apps.apple.com/de/app/wireguard/id1441195209"><img src="https://www.apple.com/de/itunes/link/images/link_badge_appstore_large_2x.png" height="55"></a> <a href="https://apps.apple.com/de/app/wireguard/id1441195209"><img src="https://www.apple.com/de/itunes/link/images/link_badge_appstore_large_2x.png" height="55"></a>
Install your Wireguard client on an Apple device by downloading the wireguard app and scanning the QR Code. Install your Wireguard client on an Apple device by downloading the wireguard app and scanning the QR Code.
Stop the containers with Stop the containers with
```shell ```shell
$ docker compose down $ docker-compose down
# To delete all data run: # To delete all data run:
$ docker compose down -v $ docker-compose down -v
``` ```
## Troubleshooting ## Troubleshooting
### - (Raspberry Pi) Kernel Headers ### - (Raspberry Pi) Kernel Headers
On Raspberry Pi run `sudo apt update && sudo apt upgrade && sudo apt install raspberrypi-kernel-headers` and reboot before starting Wireguard. On Raspberry Pi run `sudo apt update && sudo apt upgrade && sudo apt install raspberrypi-kernel-headers` and reboot before starting Wireguard.
Other Ubuntu / Debian based systems may need to install the kernel-headers too. Run `sudo apt update && sudo apt upgrade && sudo apt install linux-headers-$(uname -r)` Other Ubuntu / Debian based systems may need to install the kernel-headers too. Run `sudo apt update && sudo apt upgrade && sudo apt install linux-headers-$(uname -r)`
### - Server Mode Options ### - Server Mode Options
To create new clients or display existing ones, take a look at the "[Server Mode](https://hub.docker.com/r/linuxserver/wireguard)" section To create new clients or display existing ones, take a look at the "[Server Mode](https://hub.docker.com/r/linuxserver/wireguard)" section