Simple docker https configuration for strapi using traefik
- https://github.com/containous/traefik
- https://github.com/strapi/strapi
- https://github.com/postgres/postgres (for this example)
- Clone this repository (or fork it)
git clone git@github.com:stafyniaksacha/strapi-traefik-https.git
cd ./strapi-traefik-https
- Create a new Strapi project in
./strapi
folder
yarn create strapi-app strapi
or copy your project to
./strapi
or create a symlink to your existing project to./strapi
or clone a git submodule into./strapi
- Add
strapi-connector-bookshelf
andpg
packages to strapi project
cd ./strapi
yarn add strapi-connector-bookshelf pg
- Update Strapi configuration
// ./strapi/config/database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: env('DATABASE_HOST', 'postgres'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'postgresdb'),
username: env('DATABASE_USERNAME', 'postgresuser'),
password: env('DATABASE_PASSWORD', 'postgrespassword'),
},
options: {},
},
},
});
// ./strapi/config/server.js
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: `https://${env('STRAPI_URL', '127.0.0.1')}/`,
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET'),
},
}
});
- Create docker network
docker network create my-app-services
- Start the whole stack
docker-compose up
Strapi admin: https://strapi.127.0.0.1.xip.io/admin
Traefik dashboard: https://traefik.127.0.0.1.xip.io/ (htpasswd auth: user/pass)
Traefik is binded to the host network:
using xip.io service allow us to have a wildcard dns pointing to 127.0.0.1
You can change
./traefik/htpasswd
file to change http auth for traefik dashboard
- install
node_modules
from your host
yarn
- start your stack with
docker-compose.dev.yml
CURRENT_UID=$(id -u):$(id -g) docker-compose -f docker-compose.dev.yml up
CURRENT_UID
is used to bind your host user to the docker container user
so files created inside the container or outside remain the same (no fs erros !)
Name | Default | Description |
---|---|---|
HOST | 127.0.0.1.xip.io |
main host for all services |
DOCKER_SERVICES_RESTART | no |
docker auto restart policy, can be always
|
POSTGRES_DB | postgresdb |
postgres default database name |
DATABASE_USERNAME | postgresuser |
postgres default user name |
DATABASE_PASSWORD | postgrespassword |
postgres default user password |
ADMIN_JWT_SECRET | jwtsecret |
strapi admin jwt token (since 3.1.x) |
Generate a folder in ./backups
directory containing:
- strapi uploaded media
./backups/YYYYMMDD-HHmm/strapi_uploads.tar.gz
- postgres dump
./backups/YYYYMMDD-HHmm/dump_postgres.sql
chmod +x ./backup.sh
./backup.sh