Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kevinadhiguna/strapi-dockerize

๐Ÿ“ฆ A Strapi app powered by Docker and docker-compose. Also a guide to configure your Strapi app with hosted database service such as MongoDB Atlas.
https://github.com/kevinadhiguna/strapi-dockerize

aws docker docker-compose graphql mongodb mongodb-atlas strapi strapi-docker strapi-dockerize yarn

Last synced: about 2 months ago
JSON representation

๐Ÿ“ฆ A Strapi app powered by Docker and docker-compose. Also a guide to configure your Strapi app with hosted database service such as MongoDB Atlas.

Awesome Lists containing this project

README

        





Strapi Dockerize

Strapi Dockerize



[![Build With Yarn](https://img.shields.io/badge/build%20with-yarn-028fe4.svg?style=flat-square)](https://yarnpkg.com/)
[![Build With Docker](https://img.shields.io/badge/build%20with-docker-2496ED.svg?style=flat-square)](https://www.docker.com/)


A Strapi app powered by Docker and docker-compose.


Report Bug
ยท
Request a Feature



Strapi
JavaScript
Docker
AWS
MongoDB Atlas
GitLab CI


## โš ๏ธ Warning

This project works only on NodeJS v10.16.0 - v14.x.x. Please have a look at this [issue](https://github.com/kevinadhiguna/strapi-dockerize/issues/4) for more.


## ๐Ÿ“š Table of Contents

1. [๐ŸŒˆ About this project](#-about-this-project)
2. [โœจ What collection-type is inside this project?](#-what-collection-type-is-featured-in-this-project)
3. [๐Ÿ“– How to run](#-how-to-run)
- ๐Ÿงถ using `yarn`
- ๐Ÿ‹ using `docker-compose`
4. [โš™๏ธ Set up application configuration](#%EF%B8%8F-set-up-application-configuration-env-)
5. [๐Ÿ“ Executing commands inside the Docker container](#-executing-commands-inside-the-docker-container)
6. [๐Ÿ–ผ๏ธ Pull this project's docker image from DockerHub](#%EF%B8%8F-pull-this-projects-docker-image-from-dockerhub)
7. [๐Ÿ”’ Reset admin password in Strapi client (Strapi with UI)](#-reset-admin-password-in-strapi-client-strapi-with-ui)
8. [๐Ÿ’ป Related repositories](#-related-repositories)
9. [๐Ÿ“ฐ Related articles](#-related-articles)


## ๐ŸŒˆ About this project

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.


## โœจ What collection-type is featured in this project?

You can think collection-type as an API generated by Strapi. In this project, `Juventus` collection-type, is provided as a template. This is how it looks :

Collection-Type

The `position` has enumeration data type but this is how the auto-generated GraphQL schema (only for the `Juventus` content-type data) looks :
```graphql
enum ENUM_JUVENTUS_POSITION {
GK
DF
MF
FW
}

type Juventus {
id: ID!
_id: ID!
createdAt: DateTime!
updatedAt: DateTime!
name: String
number: Int
age: Int
country: String
appearences: Int
goals: Int
minutesPlayed: Int
position: ENUM_JUVENTUS_POSITION
profpic: UploadFile
published_at: DateTime
}
```

Now, it is clear that available options for `position` are : `GK`. `DF`, `MF`, `FW`.

In addition, there is another content-type named `facility`:

facility

You can create a database such as in MongoDB Atlas or in your local machine (laptop) to use this Strapi project. In addition, if you want to integrate this Strapi app with client side (front-end web), you can use these repos :
1. Ant Design Pro Strapi with Apollo GraphQL client
2. Ant Design Pro Strapi with URQL GraphQL client


## ๐Ÿ“– How to Run

1. Clone this repository :
```bash
git clone https://github.com/kevinadhiguna/strapi-dockerize
```

2. Change directory
```bash
cd strapi-dockerize
```

3. Install dependencies :
```bash
yarn
```

4. Create a `.env` file which stores application configuation, based on the `.env.example` file:
```bash
cp .env.example .env
```

5. Fill in the `.env` file with the application configuration. This step migth be quite long, please refer the [set up application configuration](#%EF%B8%8F-set-up-application-configuration-env-) section.

6. Run your Strapi app :

using `yarn`
```bash
yarn develop
```

using `docker-compose`
```bash
doocker-compose up
```


### โš ๏ธ Prerequisites of using `docker` and `docker-compose`
Please make sure you have Docker and docker-compose installed in your machine. Please refer here to install them :
1. [Docker](https://docs.docker.com/engine/install/) installation
2. [Docker compose](https://docs.docker.com/compose/install/) installation



### โš™๏ธ Set up application configuration (`.env`) :

#### *DATABASE_HOST*

If you run your database locally or in your computer, fill :

```bash
DATABASE_HOST=127.0.0.1
```

Otherwise, please enter your database host URL, such as :

```bash
DATABASE_HOST=cluster3.abc65.mongodb.net
```

The above is an example if you host your database in [MongoDB Atlas](https://www.mongodb.com/cloud/atlas).


#### *DATABASE_SRV*

Value of Database SRV in MongoDB. It could be either `true` or `false` as it is boolean. For example :

```bash
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](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwjl6OTUjOXwAhWY4nMBHa4RBgkQFjACegQIBhAD&url=https%3A%2F%2Fdeveloper.mongodb.com%2Fcommunity%2Fforums%2Ft%2Fmongodb-or-mongodb-srv%2F1654&usg=AOvVaw1nNUDlH5GVNZDFSL0jl2kj) for more.


#### *DATABASE_PORT*

Port that your Strapi app interacts with database management system (DBMS). For example :

```bash
DATABASE_PORT=27017
```


#### *DATABASE_NAME*

The database name in database management system (e.g. : MongoDB, MySQL, PostgreSQL). For instance :

```bash
DATABASE_NAME=myStrapiApp
```


#### *DATABASE_USERNAME*

The username of your database that you use in your Strapi app. For instance :

```bash
DATABASE_USERNAME=admin
```


#### *DATABASE_PASSWORD*

The password of your database that you use in your Strapi app. For instance :

```bash
DATABASE_PASSWORD=admin123
```


#### *DATABASE_SSL*

Usually, you set this field if your database in your Strapi app is hosted, for example :
- [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) for MongoDB
- [Free MySQL Hosting](https://www.freemysqlhosting.net/) for MySQL
- [ElephantSQL](https://www.elephantsql.com/) for PostgreSQL

Then in order to establish a secure connection, you want enable SSL. If so, set :

```bash
DATABASE_SSL=true
```

This fields is boolean. Hence, you can either set it to `true` or `false` only.


#### *CORS_ORIGIN*

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 :
```bash
CORS_ORIGIN=http://192.168.1.4:1337,http://192.168.1.4:3000
```


#### *AWS_ACCESS_KEY_ID*

For example :

```bash
AWS_ACCESS_KEY_ID=DGHY4REH7IUVDF908UNV
```


#### AWS_SECRET_ACCESS_KEY

For example :

```bash
AWS_SECRET_ACCESS_KEY=3bFhYF76zFG+5F78436KJ8bH3x19TALuIxytfNc/
```


#### *AWS_REGION*

For example :
```bash
AWS_REGION=eu-west-2
```

Please see [AWS service endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html) for details.


#### *EMAIL_DEFAULT_FROM*

An email address your Strapi app will send an email from. For example :

```bash
[email protected]
```


#### *EMAIL_DEFAULT_REPLY_TO*

An email address your Strapi app will be receiving emails. For example :

```bash
[email protected]
```


#### *AWS_BUCKET*

For example :
```bash
AWS_BUCKET=mybucket.mydomain.com
```


#### *AWS_S3_STORAGE_CLASSES*

For example :
```bash
AWS_S3_STORAGE_CLASSES=S3 Standard
```

You can read more about [AWS Storage Classes](https://aws.amazon.com/s3/storage-classes/).


#### *CLOUD_NAME*

This is the cloud name of your Coudinary account.

This looks like :
```bash
CLOUD_NAME=ehsjuvnxpz
```

Please leave it blank if your Strapi app foes not use Cloudinary.


#### *API_KEY*

This is API key from Cloudinary.

For instance :
```bash
API_KEY=253857109845223
```

You can leave it blank if you do not use Cloudinary.


#### *API_SECRET*

This is API secret from Cloudinary.

For example :
```bash
API_SECRET=DBVrte27_GtyrIUxFGydk_R8tRX
```

If you do not use Cloudinary, you can leave it blank.


#### *SENTRY_DSN*

This is a Sentry DSN that you obtain from Sentry if you use it. Otherwise, leave it blank.

For example :
```bash
SENTRY_DSN=https://[email protected]/6712395
```


#### *HOST*

Simply open terminal and type `ip addr show` (MacOS / Linux-based OS) or `ipconfig` (Windows). You should see like `192.168.1.4` which is the value of this variable.

Example :
```bash
HOST=http://192.168.1.4
```


#### *PORT*

Specify the port that you want to run.

For example :
```bash
PORT=1337
```


#### *ADMIN_JWT_SECRET*

Generate a secure token is required for superadmin authentication.

In terminal, please type :
```bash
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 :

```bash
ADMIN_JWT_SECRET=ErhxCk10YqNCImwodl5Ml/Maqnw46oTyLjr+9Na4bjmJSLVWnCS90BJRAAkLsspj98caylAJgikBO9ZS0jEiOQ==
```


#### *NODE_ENV*

This refers to the environment that your application runs. It could be `development`, `staging`, `production`, or something else.

For example :
```bash
NODE_ENV=development
```




## ๐Ÿ“ Executing commands inside the Docker container

You can run:
```bash
docker-compose exec /bin/sh
```

or

```bash
docker-compose exec /bin/sh
```




## ๐Ÿ”’ Reset Admin password in Strapi client (Strapi with UI)

You can reset Strapi admin password by running this command:

### using Yarn
```bash
yarn strapi admin:reset-user-password --email= --password=
```

### using NPM
```bash
npm run strapi admin:reset-user-password --email= --password=
```

However if you have installed Strapi globally (not recommended), you can run this command:

```bash
strapi admin:reset-user-password --email= --password=
```


Example case:

You have `[email protected]` registered as the admin email for login credential in Strapi client but you forgot the password. If you use Yarn and want to reset the password to `Kaidoe12345`, you can do so by running :

```bash
yarn strapi admin:reset-user-password [email protected] --password=Kaidoe12345
```




## ๐Ÿ’ป Related Repositories

Please feel free to have a look at :
- [Strapi MySQL - docker-compose](https://github.com/kevinadhiguna/strapi-mysql-docker)
- [Strapi MariaDB - docker-compose](https://github.com/kevinadhiguna/strapi-mariadb-docker)
- [Strapi MongoDB - docker-compose](https://github.com/kevinadhiguna/strapi-mongo-docker)
- [Strapi PostgreSQL - docker-compose](https://github.com/kevinadhiguna/strapi-postgresql-docker)




## ๐Ÿ“ฐ Related Articles

- [How to setup Amazon S3 upload provider in your Strapi app](https://dev.to/kevinadhiguna/how-to-setup-amazon-s3-upload-provider-in-your-strapi-app-1opc)
- [How to setup AWS SES email provider in your Strapi app](https://dev.to/kevinadhiguna/how-to-setup-aws-ses-email-provider-in-your-strapi-app-2lf2)
- [What is CORS ? How to configure CORS in Strapi ?](https://dev.to/kevinadhiguna/what-is-cors-how-to-configure-cors-in-strapi-461b)
- [How to disable telemetry in Strapi](https://dev.to/kevinadhiguna/disable-telemetry-in-strapi-2egf)

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](https://github.com/kevinadhiguna/strapi-dockerize/issues). Thanks!


[![Visits Badge](https://badges.pufler.dev/visits/kevinadhiguna/strapi-dockerize)](https://github.com/kevinadhiguna)