Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 7, 2024. It is now read-only.
/strapi-dockerPublic archive

Install and run your first Strapi project using Docker

License

NotificationsYou must be signed in to change notification settings

strapi/strapi-docker

Repository files navigation

Strapi containerized

⚠️ This image is only for Strapi v3. For now, we will not update it for v4.

However, to build an image compatible with Strapi v4, we recommend you check out this tool created by the Strapi Community:https://github.com/strapi-community/strapi-tool-dockerize


Strapi

API creation made simple, secure and fast.The most advanced open-source Content Management Framework to build powerful API with no effort.


TravisDocker Pulls

Images

Strapi comes with two images:strapi/strapi andstrapi/base.

Usestrapi/strapi to create a new project or run a project on your host machine.

Usestrapi/base to build a Dockerfile and create an image for your app.

How to usestrapi/strapi

This image allows you to create a new strapi project or run a project from your host machine. The default command that will run in your project isstrapi develop.

Creating a new project

When running this image, strapi will check if there is a project in the/srv/app folder of the container. If there is nothing then it will run thestrapi new command in the container /srv/app folder. You can create a new project by running this command.

docker run -it -p 1337:1337 -v`pwd`/project-name:/srv/app strapi/strapi

This command creates a project with an SQLite database. Then starts it on port1337.

The-v option creates aproject-name folder on your computer that will be shared with the docker container.Once the project is created it will be available in this folder on your computer.

Environment variables

When creating a new project with this image you can pass database configurations to thestrapi new command.

  • DATABASE_CLIENT a database provider supported by Strapi: (sqlite, postgres, mysql ,mongo).
  • DATABASE_HOST database host.
  • DATABASE_PORT database port.
  • DATABASE_NAME database name.
  • DATABASE_USERNAME database username.
  • DATABASE_PASSWORD database password.
  • DATABASE_SSL boolean for SSL.
  • EXTRA_ARGS pass extra args to thestrapi new.

Example

You can create a strapi project that will connect to a remote postgres database like so:

docker run -it \  -e DATABASE_CLIENT=postgres \  -e DATABASE_NAME=strapi \  -e DATABASE_HOST=0.0.0.0 \  -e DATABASE_PORT=5432 \  -e DATABASE_USERNAME=strapi \  -e DATABASE_PASSWORD=strapi \  -p 1337:1337 \  -v`pwd`/project-name:/srv/app \  strapi/strapi

You can also create projects using docker-compose. See examples of using these variables with docker-compose in theexamples folder.

Running a project from your host machine

You can also usestrapi/strapi to run a project you already have created (or cloned for a repo) on your computer.

First make sure to delete thenode_modules folder if you have already installed your dependencies on your host machine. Then run:

cd my-projectdocker run -it -p 1337:1337 -v`pwd`:/srv/app strapi/strapi

This will start by installing the dependencies and then runstrapi develop in the project.

Environment variables

If you are using environment variables in your code you can pass them with the -e option (e.gdocker run -e ENV_VAR=sth ...).

You can for example set your database configuration with environment variables.Because the default container command isstrapi develop you will need to update yourdevelopment database configuration following theproduction example in thedocumentation. Then you can run:

docker run -it \  -e DATABASE_NAME=strapi \  -e DATABASE_HOST=0.0.0.0 \  -e DATABASE_PORT=1234 \  -e DATABASE_USERNAME=strapi \  -e DATABASE_PASSWORD=strapi \  -p 1337:1337 \  -v`pwd`/project-name:/srv/app \  strapi/strapi

Upgrading Strapi in Docker container

  • Important! Upgradingstrapi/strapi Docker image tagdoes not upgrade Strapi version.
    • Strapi NodeJS application builds itself during first startup only, if detects empty folder and is normally stored in mounted volume. Seedocker-entrypoint.sh.
  • To upgrade, first follow the guides (general andversion-specific) to rebuild actual Strapi NodeJS application. Secondly, update docker tag to match the version to avoid confusion.

How to usestrapi/base

When deploying a strapi application to production you can use docker to package your whole app in an image. You can create a Dockerfile in your strapi project like the one in./examples/custom

Building the images in this repository

You can build the images with the build command. To see the options run:

yarn install./bin/build.js --help

About

Install and run your first Strapi project using Docker

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors35


[8]ページ先頭

©2009-2025 Movatter.jp