Dockerized strapi production vs development

I have mainly a conceptual issue with serving strapi. I’ve a project that uses the ‘docker-strapi’ approach. Whenever I do docker-compose up it starts the strapi server on development mode.

I wanted to know if is there any difference (in performance and/or security) to have it run using the NODE_ENV=production flag set (it’ll perform a build and then a start).

Is there any other way of making it more production ready? Or serving strapi like this is more than enough?

I saw the documentation for deploying, and they recommend using pm2, but that is using strapi without docker (and docker-compose), I think that it doesn’t make any sense to have pm2 for running the docker-compose up command (correct me if I’m wrong).


Using production mode do some optimizations on the build and also you can’t use the content-builder. In development you can use it.
It’s advised to use production for production env and development for your local or test environments.

The use of PM2 etc is advised but you can run it differently, it really depends on how you are serving your application.

You could build a docker image then serve that with ECS and other cloud containers.

Personally I run my own server with Dokku (like heroku) and have it build and do the serve for me.

Thanks for the reply! One question that I have is, having done the build, do I really need to do strapi start or I can simply serve it using for instance NGINX? I am mainly asking this because of two things, the cron tasks and the lifecycle hooks that I’ve set. If I don’t do the strapi start I think that this functionality will be lost, or am I wrong?

The main question here is actually, is doing a strapi start valid (in terms of performance/security/etc.) for production usage?

Will you be willing to share your dokku configuration? I don’t actually know much abount serving apps that’s why I might be asking these kind of silly questions.

I’m in the process of writing a dokku guide but it’s not ready yet.

But in simple terms you need to run strapi start to make the server itself run. So like any nodeJS application running.

If you are running docker itself :slight_smile: then something like this should run it

FROM node:14-alpine
ARG NODE_ENV=production
COPY ./package.json ./
COPY ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g
RUN yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
CMD ["yarn", "start"]

You will have to pass it develop as an argument else it will default to production.
With Dokku I have set it up to serve the docker image itself, so no more config is needed, except port mapping.

1 Like

Awesome! Thanks so much for your help! Now its clear to me that I must do a strapi start for the app to run in production

You’re welcome

And how do you develop a new content type in production. Are you going to develop it in dev environment and move it to production? How do you decided to migrate it to production?

You make the types and everything you need in development. And add the data in production. :blush:

Thank you for the comment :slight_smile: