Skip to content

Commit af92c75

Browse files
authored
docs: updating Docker Compose for production (#1333)
1 parent 2dc7382 commit af92c75

File tree

1 file changed

+11
-103
lines changed

1 file changed

+11
-103
lines changed

deployment/docker-compose.md

Lines changed: 11 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,9 @@ e.g. [Docker Hub](https://hub.docker.com/), [Google Container Registry](https://
1212
would pull the pre-built images from the container registry. This maintains a separation of concerns between the build
1313
environment and the production environment.
1414

15-
## Installing the Docker Compose Setup for Production
15+
## Deploying for Production
1616

17-
If you are using the [API Platform Distribution](../distribution/index.md), we provide a [ready-to-deploy Docker Compose
18-
setup for production](https://github.com/api-platform/docker-compose-prod), with (optional) [Let's Encrypt](https://letsencrypt.org/)
19-
integration.
20-
21-
It is designed to be used as a companion to the distribution, and as such it needs to be placed inside a subdirectory at
22-
the top level of the distribution project:
23-
24-
```console
25-
wget -O - https://github.com/api-platform/docker-compose-prod/archive/master.tar.gz | tar -xzf - && mv docker-compose-prod-master docker-compose-prod
26-
git add docker-compose-prod
27-
```
28-
29-
Then commit the changes to your git repository. The `docker-compose-prod` directory should be checked in.
17+
To build images for production, you have to use the `docker-compose.prod.yml` file with Docker Compose.
3018

3119
## Building and Pushing the Docker Images
3220

@@ -57,14 +45,13 @@ These steps should be performed in a CI job (recommended) or on your development
5745
2. Build the Docker images:
5846

5947
```shell
60-
docker-compose -f docker-compose-prod/docker-compose.build.yml pull --ignore-pull-failures
61-
docker-compose -f docker-compose-prod/docker-compose.build.yml build --pull
48+
docker-compose -f docker-compose.yml -f docker-compose.prod.yml build --pull
6249
```
6350

6451
3. Push the built images to the container registry:
6552

6653
```shell
67-
docker-compose -f docker-compose-prod/docker-compose.build.yml push
54+
docker-compose -f docker-compose.yml -f docker-compose.prod.yml push
6855
```
6956

7057
## Pulling the Docker Images and Running the Services
@@ -77,100 +64,21 @@ These steps should be performed on the production server.
7764
confused with `api/.env` which is used by the Symfony application). For example:
7865

7966
```shell
80-
ADMIN_HOST=admin.example.com
81-
ADMIN_IMAGE=registry.example.com/api-platform/admin
82-
API_HOST=api.example.com
83-
APP_SECRET=3c857494cfcc42c700dfb7a6
84-
CLIENT_HOST=example.com,www.example.com
85-
CLIENT_IMAGE=registry.example.com/api-platform/client
86-
CORS_ALLOW_ORIGIN=^https://(?:\w+\.)?example\.com$
87-
DATABASE_URL=postgres://api-platform:4e3bc2766fe81df300d56481@db/api
88-
MERCURE_ALLOW_ANONYMOUS=0
89-
MERCURE_CORS_ALLOWED_ORIGINS=https://example.com,https://admin.example.com
90-
MERCURE_HOST=mercure.example.com
91-
MERCURE_JWT_KEY=4121344212538417de3e2118
92-
MERCURE_JWT_SECRET=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.B0MuTRMPLrut4Nt3wxVvLtfWB_y189VEpWMlSmIQABQ
93-
MERCURE_SUBSCRIBE_URL=https://mercure.example.com/hub
94-
NGINX_IMAGE=registry.example.com/api-platform/nginx
95-
PHP_IMAGE=registry.example.com/api-platform/php
96-
POSTGRES_PASSWORD=4e3bc2766fe81df300d56481
97-
REACT_APP_API_ENTRYPOINT=https://api.example.com
98-
TRUSTED_HOSTS=^(?:localhost|api|api\.example\.com)$
99-
VARNISH_IMAGE=registry.example.com/api-platform/varnish
67+
SERVER_NAME=api.example.com
68+
MERCURE_PUBLISHER_JWT_KEY=someKey
69+
MERCURE_SUBSCRIBER_JWT_KEY=someKey
10070
```
10171

10272
**Important**: Please make sure to change all the passwords, keys and secret values to your own.
10373

104-
2. Set up a redirect from e.g. `www.example.com` to `example.com`:
105-
106-
```shell
107-
mkdir -p docker-compose-prod/docker/nginx-proxy/vhost.d
108-
echo 'return 301 https://example.com$request_uri;' > docker-compose-prod/docker/nginx-proxy/vhost.d/www.example.com
109-
```
110-
111-
**Note**: If you do not want such a redirect, or you want it to be the other way round, please adapt to suit your needs.
112-
113-
3. *(optional)* Set up the Let's Encrypt integration.
114-
115-
**Note**: If you are using Cloudflare, you might consider using their [free SSL/TLS encryption](https://www.cloudflare.com/ssl/)
116-
setup as a simpler alternative. But if you would prefer to have full control, read on.
117-
118-
Make sure the environment variables required for the Let's Encrypt integration are set.
119-
120-
You could set the environment variables in the `.env` file at the top level of the distribution project (not to be
121-
confused with `api/.env` which is used by the Symfony application). For example:
122-
123-
```shell
124-
125-
LEXICON_CLOUDFLARE_AUTH_TOKEN=9e06358f74cbce70602c22fc3279f0aee3077
126-
127-
```
128-
129-
**Note**: If you are not using [Cloudflare DNS](https://www.cloudflare.com/dns/), please see [the documentation on
130-
how to pass the correct environment variables to Lexicon](https://github.com/adferrand/docker-letsencrypt-dns#configuring-dns-provider-and-authentication-to-dns-api).
131-
132-
Configure the (sub)domains for which you want certificate(s) to be issued for in `docker-compose-prod/docker/letsencrypt/domains.conf`.
133-
For example, to request a wildcard certificate for `*.example.com` and `example.com`:
134-
135-
```shell
136-
*.example.com example.com autorestart-containers=api-platform_nginx-proxy_1
137-
```
138-
139-
**Note**: Replace the `api-platform` prefix in `api-platform_nginx-proxy_1` with your [Docker Compose project name
140-
(it defaults to the project directory name)](https://docs.docker.com/compose/reference/envvars/#compose_project_name).
141-
142-
4. Pull the Docker images.
143-
144-
If you are **not** using the (optional) Let's Encrypt integration:
74+
2. Pull the Docker images.
14575

14676
```console
147-
docker-compose -f docker-compose-prod/docker-compose.yml pull
77+
docker-compose -f docker-compose.yml -f docker-compose.prod.yml pull
14878
```
14979

150-
If you are using the (optional) Let's Encrypt integration:
80+
3. Bring up the services.
15181

15282
```console
153-
docker-compose -f docker-compose-prod/docker-compose.yml -f docker-compose-prod/docker-compose.letsencrypt.yml pull
83+
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
15484
```
155-
156-
5. Bring up the services.
157-
158-
If you are **not** using the (optional) Let's Encrypt integration:
159-
160-
```console
161-
docker-compose -f docker-compose-prod/docker-compose.yml up -d
162-
```
163-
164-
If you are using the (optional) Let's Encrypt integration:
165-
166-
```console
167-
docker-compose -f docker-compose-prod/docker-compose.yml -f docker-compose-prod/docker-compose.letsencrypt.yml up -d
168-
```
169-
170-
## Running the Docker Compose Setup for Production Locally
171-
172-
Sometimes, you may need to run a production-like setup locally; for example, for [end-to-end testing](../distribution/testing.md#using-the-api-platform-distribution-for-end-to-end-testing)
173-
or to troubleshoot problems which can only be reproduced with a production setup (e.g. Varnish errors or cache misses).
174-
175-
You may (re)use the same [Docker Compose setup for production](https://github.com/api-platform/docker-compose-prod) we
176-
have [installed above](#installing-the-docker-compose-setup-for-production).

0 commit comments

Comments
 (0)