Simply copy and paste the following command line in your terminal to create your first Strapi project.
npx create-strapi-app
my-project
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.
1
2
3
4
5
6
7
8
version: '3'
services:
strapi:
image: strapi/strapi
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
This will create a postgresql database, a Strapi project and link it to the database.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
version: '3'
services:
strapi:
image: strapi/strapi
environment:
DATABASE_CLIENT: postgres
DATABASE_NAME: strapi
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
depends_on:
- postgres
postgres:
image: postgres
environment:
POSTGRES_DB: strapi
POSTGRES_USER: strapi
POSTGRES_PASSWORD: strapi
volumes:
- ./data:/var/lib/postgresql/data
This will create a Mongodb database, a Strapi project and link it to the database.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
version: '3'
services:
strapi:
image: strapi/strapi
environment:
DATABASE_CLIENT: mongo
DATABASE_NAME: strapi
DATABASE_HOST: mongo
DATABASE_PORT: 27017
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
depends_on:
- mongo
mongo:
image: mongo
environment:
MONGO_INITDB_DATABASE: strapi
MONGO_INITDB_ROOT_USERNAME: strapi
MONGO_INITDB_ROOT_PASSWORD: strapi
volumes:
- ./data:/data/db
This will create a MySQL database, a Strapi project and link it to the database.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
version: '3'
services:
strapi:
image: strapi/strapi
environment:
DATABASE_CLIENT: mysql
DATABASE_HOST: mysql
DATABASE_PORT: 3306
DATABASE_NAME: strapi
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
DATABASE_SSL: 'false'
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
depends_on:
- mysql
mysql:
image: mysql
command: mysqld --default-authentication-plugin=mysql_native_password
volumes:
- ./data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: strapi
MYSQL_DATABASE: strapi
MYSQL_USER: strapi
MYSQL_PASSWORD: strapi
This will create a MariaDB database, a Strapi project and link it to the database.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
version: '3'
services:
strapi:
image: strapi/strapi
environment:
DATABASE_CLIENT: mysql
DATABASE_HOST: mariadb
DATABASE_PORT: 3306
DATABASE_NAME: strapi
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
DATABASE_SSL: 'false'
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
depends_on:
- mariadb
mariadb:
image: mariadb
volumes:
- ./data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: strapi
MYSQL_DATABASE: strapi
MYSQL_USER: strapi
MYSQL_PASSWORD: strapi
You are now ready to start a Strapi project using Docker compose! First you want to pull the latest images.
1
docker-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 ;)
1
2
3
docker-compose up # Executes Docker images without detaching the terminal
# or
docker-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