Docker image for Strapi development, based on gilhardl/node
Start CLI :
docker run -it --name strapi -v /path/to/your/project:/usr/src/api gilhardl/strapi
Start CLI and expose port to be able to start the app :
docker run -it --name strapi -v /path/to/your/project:/usr/src/api gilhardl/strapi -p 1337:1337 --link yourapp-db:mongo
Note :
yourapp-dbis the name of your MongoDB container- If you don't want to start the app, you don't need to specify
-p 1337:1337or--link yourapp-db:mongoparameters.
- Create a volume for MongoDB data (if not exist)
docker volume create mongodb-data
- Run MongoDB container for your database
docker run -it --name yourapp-db -p 27017:27017 -v mongodb-data:/data/db -e MONGO_INITDB_DATABASE=yourapp mongo
- Run Strapi container to use Strapi CLI
docker run -it --name strapi -v /path/to/your/project:/usr/src/api -p 1337:1337 --link yourapp-db:mongo gilhardl/strapi
- Use Strapi CLI
Create a project :
strapi new yourapp-api
? Choose your installation type Custom (manual settings)
? Choose your main database: MongoDB
? Database name: yourapp
? Host: yourapp-db
? +srv connection: false
? Port (It will be ignored if you enable +srv): 27017
? Username:
? Password:
? Authentication database (Maybe "admin" or blank):
? Enable SSL connection: false
...
Start API :
strapi start
Create a file named docker-compose.yml at your project root like the following :
version: '3'
services:
api:
container_name: yourapp-api
build: .
image: gilhardl/strapi
ports:
- 1337:1337
volumes:
- .:/usr/src/api/
depends_on:
- db
command: strapi start
restart: always
db:
container_name: yourapp-db
image: mongo
environment:
- MONGO_INITDB_DATABASE=yourapp
ports:
- 27017:27017
volumes:
- mongodb-data:/data/db
restart: always
volumes:
mongodb-data:
Start database and API :
docker-compose up
MIT