- π About this project
- π How to Run
- π§Ά using
yarn
- Create a
.env
file then set up Environment Variables - Run your Strapi app with
yarn
- Create a
- π using
docker-compose
- Create a
docker-compose.yml
then configure it - Run your Strapi app with
docker-compose
- Create a
- π§Ά using
- π° Related Articles
This is a Strapi app powered by Docker and docker-compose. Nevertheless, this app provides an example and a guide to configure your Strapi app with hosted database service such as MongoDB Atlas.
- Clone this repository :
git clone https://github.com/kevinadhiguna/strapi-dockerize
- Change directory
cd strapi-dockerize
- Install dependencies (using
yarn
) :
yarn
- Run your Strapi app either with
yarn
ofdocker-compose
:
- If using
yarn
, please create.env
then set up environment variables. - If using
docker-compose
, please createdocker-compose.yaml
then configure docker-compose.
- Please create a
.env
file based on.env.example
file and fill in the variables mentioned below :
If you run your database locally or in your computer, fill :
DATABASE_HOST=127.0.01
Otherwise, please enter your database host URL, such as :
DATABASE_HOST=cluster3.abc65.mongodb.net
The above is an example if you host your database in MongoDB Atlas.
Value of Database SRV in MongoDB. It could be either true
or false
as it is boolean. For example :
DATABASE_SRV=true
SRV is a way to specify a single hostname that resolves to multiple host names. When using SRV, the driver conducts an SRV lookup to get the actual names of all of the hosts. Also, when using SRV, the driver does lookups for TXT records, which can contain specific URI options to configure the driver.
Please have a look at MongoDB community forum for more.
Port that your Strapi app interacts with database management system (DBMS). For example :
DATABASE_PORT=27017
The database name in database management system (e.g. : MongoDB, MySQL, PostgreSQL). For instance :
DATABASE_NAME=myStrapiApp
The username of your database that you use in your Strapi app. For instance :
DATABASE_USERNAME=admin
The password of your database that you use in your Strapi app. For instance :
DATABASE_PASSWORD=admin123
Usually, you set this field if your database in your Strapi app is hosted, for example :
- MongoDB Atlas for MongoDB
- Free MySQL Hosting for MySQL
- ElephantSQL for PostgreSQL
Then in order to establish a secure connection, you want enable SSL. If so, set :
DATABASE_SSL=true
This fields is boolean. Hence, you can either set it to true
or false
only.
Please add URL/IP address of :
- App's client-side (a Web App and/or a Mobile app)
- Strapi Admin Panel
CORS only cares three aspects, namely :
- Scheme (e.g. :
https
,http
, etc.) - URL/IP address
- Port
So, if your app's client-side and Strapi admin panel run on http://192.168.1.4:3000 and http://192.168.1.4:1337 respectively, you should write :
CORS_ORIGIN=http://192.168.1.4:1337,http://192.168.1.4:3000
For example :
AWS_ACCESS_KEY_ID=DGHY4REH7IUVDF908UNV
For example :
AWS_SECRET_ACCESS_KEY=3bFhYF76zFG+5F78436KJ8bH3x19TALuIxytfNc/
For example :
AWS_REGION=eu-west-2
Please see AWS service endpoints for details.
An email address your Strapi app will send an email from. For example :
An email address your Strapi app will be receiving emails. For example :
For example :
AWS_BUCKET=mybucket.mydomain.com
For example :
AWS_S3_STORAGE_CLASSES=S3 Standard
You can read more about AWS Storage Classes.
This is the cloud name of your Coudinary account.
This looks like :
CLOUD_NAME=ehsjuvnxpz
Please leave it blank if your Strapi app foes not use Cloudinary.
This is API key from Cloudinary.
For instance :
API_KEY=253857109845223
You can leave it blank if you do not use Cloudinary.
This is API secret from Cloudinary.
For example :
API_SECRET=DBVrte27_GtyrIUxFGydk_R8tRX
If you do not use Cloudinary, you can leave it blank.
This is a Sentry DSN that you obtain from Sentry if you use it. Otherwise, leave it blank.
For example :
SENTRY_DSN=https://[email protected]/6712395
Simply open terminal and type ifconfig
(MacOS / Linux-based OS) or ipconfig
(Windows). You should see like 192.168.1.4
which is the value of this variable.
Example :
HOST=http://192.168.1.4
Specify the port that you want to run.
For example :
PORT=1337
Generate a secure token is required for superadmin authentication.
In terminal, please type :
openssl rand 64 | base64 # (linux/macOS users)
# or
node -e "console.log(require('crypto').randomBytes(64).toString('base64'))" # (all users)
Then you should see something like this in your terminal :
ErhxCk10YqNCImwodl5Ml/Maqnw46oTyLjr+9Na4bjmJSLVWnCS90BJRAAkLsspj98caylAJgikBO9ZS0jEiOQ==
Please copy the token and assign it like this :
ADMIN_JWT_SECRET=ErhxCk10YqNCImwodl5Ml/Maqnw46oTyLjr+9Na4bjmJSLVWnCS90BJRAAkLsspj98caylAJgikBO9ZS0jEiOQ==
This refers to the environment that your application runs. It could be development
, staging
, production
, or something else.
For example :
NODE_ENV=development
- Start Strapi app :
yarn develop
- Open Strapi admin panel in a browser.
Prerequisites :
Please make sure you have Docker installed in your machine. Please refer here to install Docker.
- Assign values of environment variables in
docker-compose.yml
file
Here we specify running environment whether it is production
, staging
, development
, etc.
Using staging
and development
will turn on AWS S3 storage.
Example:
NODE_ENV: development
Name of the database client. Set to mongo
if you use MongoDB.
DATABASE_CLIENT: mongo
Host of database such as 127.0.0.1
(localhost) or a URL like cluster3.abc65.mongodb.net
if you useMongoDB Atlas.
If you run your database locally or in your computer, fill :
DATABASE_HOST: 127.0.01
Otherwise, please enter your database host URL, such as :
DATABASE_HOST: cluster3.abc65.mongodb.net
Please note that it must be string or null. Possible values : true
or false
. For instance :
DATABASE_SRV: true
Determine the port that will be used for database management system that serves this app. Below is an example :
DATABASE_PORT: 27017
Please name the database name. Let's say :
DATABASE_NAME: myStrapiApp
Username of database, such as :
DATABASE_USERNAME: admin
Generate a strong password for database, namely :
DATABASE_PASSWORD: admin123
Enable Secure Socket Layer (SSL) ? If so, please fill 'true'
otherwise 'false'
. Please note that this MUST be string or null. As an example :
DATABASE_SSL: 'true'
Put allowed Cross-Origin Resource Sharing (CORS) origin here. It is possibly only one or even more. if your app's client-side and Strapi admin panel run on http://192.168.1.4:3000 and http://192.168.1.4:1337 respectively, you should write :
CORS_ORIGIN: http://192.168.1.4:3000,http://192.168.1.4:1337
Read MDN Web Docs for more.
Generate a secure token for superadmin authentication. Below is an example :
ADMIN_JWT_SECRET: ErhxCk10YqNCImwodl5Ml/Maqnw46oTyLjr+9Na4bjmJSLVWnCS90BJRAAkLsspj98caylAJgikBO9ZS0jEiOQ==
Please refer to How to generate Admin JWT Secret above for more.
These ports are not meant for database management system but for the app. There are a couple of ports which are host port and container port. Host port is a port exposed to public. Meanwhile, container port is an internal port that will be accessed through the machine you use. In particular :
ports:
- '1337:1337'
Only if you use Amazon Web Service (AWS) :
AWS_REGION
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_BUCKET
- Run your App If you run it for the first time or make changes, please run :
docker-compose up --build
If you do not make changes but want to run the app again :
docker-compose up
π Note : If you want to check the files inside the Docker container, you can use:
docker-compose exec strapi /bin/sh
- How to setup Amazon S3 upload provider in your Strapi app
- How to setup AWS SES email provider in your Strapi app
- What is CORS ? How to configure CORS in Strapi ?
- How to disable telemetry in Strapi
Also, this article might be helpful to use this project : https://about.lovia.life/creating-strapi-app-image-with-docker/.
Should you have any questions or discussion, please feel free to ask here. Thanks!