|
1 | | -# Docker |
| 1 | +# Docker integration |
2 | 2 |
|
3 | | -- `compas init docker` |
4 | | -- Config file |
5 | | -- Resetting the containers |
| 3 | +Most of the time your application requires external services. Compas supports |
| 4 | +automatically spinning up those external services via |
| 5 | +[Docker](https://docs.docker.com/). |
| 6 | + |
| 7 | +## Getting started |
| 8 | + |
| 9 | +The docker integration is not enabled by default. You can run the following |
| 10 | +command or apply the config changes below manually. |
| 11 | + |
| 12 | +```shell |
| 13 | +compas init docker |
| 14 | +``` |
| 15 | + |
| 16 | +This creates or updates the Compas config file in `config/compas.json` with the |
| 17 | +following contents: |
| 18 | + |
| 19 | +```json |
| 20 | +{ |
| 21 | + "dockerContainers": { |
| 22 | + "compas-postgres-15": { |
| 23 | + "createArguments": "-e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e PGDATA=/var/lib/postgresql/data/pgdata -v compas-postgres-15:/var/lib/postgresql/data/pgdata -p 5432:5432", |
| 24 | + "image": "postgres:15" |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +## Config |
| 31 | + |
| 32 | +Each container definition has the following properties: |
| 33 | + |
| 34 | +- The image name, in the above example 'compas-postgres-15'. This name should |
| 35 | + either be unique over all your projects, or the container is reused across |
| 36 | + projects that specify the same name. This may be the desired behavior if you |
| 37 | + work on multiple projects that share the same set of services. |
| 38 | +- `createArguments`: Arguments to pass to the `docker create` command. See the |
| 39 | + [Docker documentation](https://docs.docker.com/engine/reference/commandline/create/) |
| 40 | + for more information. The `--name` argument and image are provided by Compas. |
| 41 | +- `image`: The image to create the container from. Anything that Docker supports |
| 42 | + works. It is advised to develop against the same versions as your production |
| 43 | + environment will have. |
| 44 | + |
| 45 | +## Limitations |
| 46 | + |
| 47 | +- Compas currently does not have any behavior to automatically stop containers. |
| 48 | +- The Docker containers will still run in the background even though you stopped |
| 49 | + the development CLI. This could cause conflicts with for example used ports |
| 50 | + when you start working on a different project. You can stop containers with |
| 51 | + `docker stop $name` and remove them with `docker rm $name`. |
0 commit comments