Strapi v4 docker

Hi,
When the docker version of strapi v4 will be available on docker hub please ?
Thank you

5 Likes

Up, I’m waiting for official image too.

You can create your own image quite simply by doing

FROM node:16-alpine
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
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
EXPOSE 1337
CMD ["yarn", "start"]
2 Likes

This doesn’t work for me. Get all kind of error messages, which i didn’t get with the latest 3.x version. After changing to node:16-bullseye, it did install correctly. I can open it, but then get some “Reload Component …” is missing Error and cannot use the page.

The autoReload feature is required to use this plugin. Start your server with strapi develop

The docker build is not meant to be used for development, if you want development it’s better to run a database in a container then use your local machine for development (Been this in V3 as well)
Note that yarn start will not run development. it would be yarn develop on the last line.

exactly - I cannot even install it without docker through npx on macos - still bunch of errors

Is there an official image available soon - any infos about that?

This helped me to bootstrap my app in v4 : How to Deploy and Scale the Official Strapi Demo App "Foodadvisor" with Kubernetes & Docker

Had to pick the v4 branch (the one mentioned in the article is missing) and to fix a missing component build problem.

For the rest it’s ok.

I hope this helps.

Still i will wait for the official image to develop my new project.

+1 Less marketing and more prio for a official docker image with latest and greatest…

Wrote my own blog how you can make your own docker image :slight_smile:

4 Likes

@Eventyret Thanks for effort and it’s nice guideline, but not without mistakes/simple enough (more in article comments section). Anyway problem with node itself is that it has so many dependencies and development is dynamic enough that any guideline will be soon outdated = not working anymore as yours is.

The docker image is key for somebody like me (non-developer) who just want’s to use that software.

I don’t understand that push back from Strapi folks as it’s for sure part of their development workflow and there are public pipeline templates which can automated that away…

I went the path with lowest resistance, looked for alternatives and continued with competitor which has self hosted free plan for small projects.

I don’t think it’s part of their development workflow :slight_smile:
Lowest path is once you get it setup and running, well it works just fine.

I mean I have so far taken the same docker image that I explained in the blog minor customizations depending on what I am using etc.

Anyone with docker can create a V4 image and you can just pull and use it.
So if you are a NON-developer, you just want strapi to work, I guess someone can just create a Strapi Image and release it, and keep it maintained.

The issue then is that it’s different for every single setup, you might want sqlite another one to have something else. And that’s where the work and why things take the time comes in.

Hopefully it comes soon, but things do take time. All I offered was a way for people to create their own images. :slight_smile:

For development, you can use this Dockerfile, its the same provided by @Eventyret , but few modifications


FROM node:16-alpine
# Installing libvips-dev for sharp Compatability
RUN apk update && apk add  build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/app
COPY ./package.json ./yarn.lock ./
# ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
RUN yarn add --verbose --platform=linuxmusl --arch=x64 sharp
# WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "develop"]

As answered on my blog, the idea of using opt/app and app is different.
You don’t want node modules inside the same folder as the app if we can help it.
The reason for it is that it gives more attack surface in a container, so it’s a security risk.

You can try to use the tool that I created for it.
As it creates the files and even a docker-compose for you.
:package: - @strapi-community/dockerize - npm
:earth_africa: - GitHub - strapi-community/strapi-tool-dockerize: Easy add support for docker to your strapi project

Placing node_modules into /opt is not working because it produces following error

error: Could not load js config file /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js

So, it is looking for file in /opt/app

Try the tool, as it was a fix for it yesterday that was released.
So try use the tool, generate the Dockerfile and see if sorts it.

Same issue, the problem is when we run yarn develop it is looking for file /opt/app/node_modules where as node_modules in just /opt path

# ENV PATH /opt/node_modules/.bin:$PATH

You commented out to tell yarn where to look for it.

Yes, I commented out and change WORKDIR to /opt/app to install node_modules where the app code resides, after that when it start, it picks that path and start working

Again that will work indeed, but it’s considered unsafe in a docker environment using nodeJS.

I never said it was wrong, I said it was bad practice.