Strapi is a self-hosted Headless CMS. It means that you can run and maintain it on your own private servers. Several solutions are available for you to get started. You can use the CLI, one of our one click buttons or use Docker compose.
The last solution will allow you to create your self-hosted strapi project with any database and will be compatible on any OS.
Docker Compose is a command-line tool that uses a specially formatted descriptor file to take multiple docker containers and assemble them into applications which can then be run on a single host.
Our VP Marketing Victor Coisne wrote a full article about it: What is Docker Compose? All you need to know!
docker-compose.yaml
file in an empty folder. This docker-compose.yaml
file will define your database, your Strapi service and links them. This will create a fresh new Strapi application where the docker-compose.yaml
file is located.However you may want to use a specific database. Find below all the possibilities:
This will just create a simple Strapi project using an SQLite database.
1version: '3'
2services:
3 strapi:
4 image: strapi/strapi
5 volumes:
6 - ./app:/srv/app
7 ports:
8 - '1337:1337'
This will create a postgresql database, a Strapi project and link it to the database.
1version: '3'
2services:
3 strapi:
4 image: strapi/strapi
5 environment:
6 DATABASE_CLIENT: postgres
7 DATABASE_NAME: strapi
8 DATABASE_HOST: postgres
9 DATABASE_PORT: 5432
10 DATABASE_USERNAME: strapi
11 DATABASE_PASSWORD: strapi
12 volumes:
13 - ./app:/srv/app
14 ports:
15 - '1337:1337'
16 depends_on:
17 - postgres
18
19 postgres:
20 image: postgres
21 environment:
22 POSTGRES_DB: strapi
23 POSTGRES_USER: strapi
24 POSTGRES_PASSWORD: strapi
25 volumes:
26 - ./data:/var/lib/postgresql/data
This will create a Mongodb database, a Strapi project and link it to the database.
1version: '3'
2services:
3 strapi:
4 image: strapi/strapi
5 environment:
6 DATABASE_CLIENT: mongo
7 DATABASE_NAME: strapi
8 DATABASE_HOST: mongo
9 DATABASE_PORT: 27017
10 DATABASE_USERNAME: strapi
11 DATABASE_PASSWORD: strapi
12 volumes:
13 - ./app:/srv/app
14 ports:
15 - '1337:1337'
16 depends_on:
17 - mongo
18
19 mongo:
20 image: mongo
21 environment:
22 MONGO_INITDB_DATABASE: strapi
23 MONGO_INITDB_ROOT_USERNAME: strapi
24 MONGO_INITDB_ROOT_PASSWORD: strapi
25 volumes:
26 - ./data:/data/db
This will create a MySQL database, a Strapi project and link it to the database.
1version: '3'
2services:
3 strapi:
4 image: strapi/strapi
5 environment:
6 DATABASE_CLIENT: mysql
7 DATABASE_HOST: mysql
8 DATABASE_PORT: 3306
9 DATABASE_NAME: strapi
10 DATABASE_USERNAME: strapi
11 DATABASE_PASSWORD: strapi
12 DATABASE_SSL: 'false'
13 volumes:
14 - ./app:/srv/app
15 ports:
16 - '1337:1337'
17 depends_on:
18 - mysql
19
20 mysql:
21 image: mysql
22 command: mysqld --default-authentication-plugin=mysql_native_password
23 volumes:
24 - ./data:/var/lib/mysql
25 environment:
26 MYSQL_ROOT_PASSWORD: strapi
27 MYSQL_DATABASE: strapi
28 MYSQL_USER: strapi
29 MYSQL_PASSWORD: strapi
This will create a MariaDB database, a Strapi project and link it to the database.
1version: '3'
2services:
3 strapi:
4 image: strapi/strapi
5 environment:
6 DATABASE_CLIENT: mysql
7 DATABASE_HOST: mariadb
8 DATABASE_PORT: 3306
9 DATABASE_NAME: strapi
10 DATABASE_USERNAME: strapi
11 DATABASE_PASSWORD: strapi
12 DATABASE_SSL: 'false'
13 volumes:
14 - ./app:/srv/app
15 ports:
16 - '1337:1337'
17 depends_on:
18 - mariadb
19
20 mariadb:
21 image: mariadb
22 volumes:
23 - ./data:/var/lib/mysql
24 environment:
25 MYSQL_ROOT_PASSWORD: strapi
26 MYSQL_DATABASE: strapi
27 MYSQL_USER: strapi
28 MYSQL_PASSWORD: strapi
You are now ready to start a Strapi project using Docker compose! First you want to pull the latest images.
1docker-compose pull
By default, running the docker-compose up
command for the first time automatically pull the images so this command is quite optionnal. This shoud take a moment, you'll be able to get a coffee ;)
1docker-compose up # Executes Docker images without detaching the terminal
2# or
3docker-compose up -d # Executes Docker images detaching the terminal:
You database should have been created and your Strapi project must be installing dependencies, building and then start!
Please note: Since we initially published this blog post, we released new versions of Strapi and tutorials may be outdated. Sorry for the inconvenience if it's the case. Please help us by reporting it here.
Maxime started to code in 2015 and quickly joined the Growth team of Strapi. He particularly likes to create useful content for the awesome Strapi community. Send him a meme on Twitter to make his day: @MaxCastres