Last active
January 16, 2020 01:30
-
-
Save mattpolzin/4ca49d8f2dde6294f8dc412bb90687c1 to your computer and use it in GitHub Desktop.
A template docker-compose file for Vapor apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
x-common: &common | |
environment: | |
SHARED_ENV_VAR1: 'value' | |
SHARED_ENV_VAR2: 'value' | |
services: | |
vapor_app: # name this whatever you want | |
<<: *common | |
image: vapor_app:latest | |
command: ./Run serve --env docker --hostname 0.0.0.0 --port 80 # --log trace | |
build: | |
context: . # means the Dockerfile is in the same folder as this docker-compose file. | |
args: | |
env: docker | |
depends_on: | |
- postgres | |
ports: | |
- '8080:80' | |
migrator: | |
<<: *common | |
image: vapor_app:latest | |
command: /bin/bash -c "echo 'y' | ./Run migrate" | |
depends_on: | |
- postgres | |
- vapor_app | |
deploy: | |
replicas: 1 # starts up automatically when swarm is started. Set to 0 to require it to be spun up manually. | |
restart_policy: | |
condition: on-failure | |
delay: 5s | |
max_attempts: 10 | |
postgres: | |
image: postgres:11.5-alpine | |
environment: | |
- POSTGRES_USER=postgres | |
- POSTGRES_PASSWORD=postgres | |
ports: | |
- '5434:5432' | |
## | |
## Setup | |
## - Put this file into the same folder as your Dockerfile and name it 'docker-compose.dev.yml' | |
## | |
## | |
## Building | |
## - Ensure you have a Dockerfile (the Vapor 4 API template ships with one). | |
## - If you are using the Dockerfile from the Vapor 4 API template, rename it | |
## from 'web.Dockerfile' to just 'Dockerfile' and change the last line | |
## from `ENTRYPOINT ./Run ...` to `CMD ./Run ...` | |
## - Start your Docker daemon (e.g. Docker for Mac). | |
## - From this folder, run `docker-compose -f docker-compose.dev.yml build`. | |
## | |
## | |
## Deploying as Swarm | |
## - Ensure your Docker Daemon is running (e.g. Docker for Mac). | |
## - Run `docker swarm init` (only needed once) | |
## - Run `docker stack up -c docker-compose.dev.yml test` | |
## - See service status: `docker service ls` | |
## - See service logs for vapor app: `docker service logs -f test_vapor_app` | |
## - Your app is at `http://127.0.0.1:8080` (or `http://localhost:8080`) | |
## | |
## | |
## Bringing things down | |
## - Run `docker stack rm test` | |
## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment