strapi-docker icon indicating copy to clipboard operation
strapi-docker copied to clipboard

Provide production image

Open maggie44 opened this issue 3 years ago • 4 comments

Hi,

Thanks for maintaining the docker image for Strapi, it is incredibly helpful for quick and easy management.

I am wondering if we could have a production version of the image? I see the production compose file (https://github.com/strapi/strapi-docker/blob/master/examples/prod/docker-compose.yml), but at the moment, all the files are mounted to the local host so a Docker pull will not update Strapi as it reuses the node_modules and pacakges.json from the host (which will always overwrite whichever version is in the container).

It would entail symlinking the files that are customised by the user to another folder, and then allowing the user to mount that folder instead of the Strapi root directory. Here is an example: https://github.com/linuxserver/docker-bookstack/blob/9b622e8d4429d2f9d624fb61815888562fe5347d/root/etc/cont-init.d/50-config#L11 . That way, on a docker-pull Strapi would be up to date.

When it comes to fixing to a certain version of Strapi, users can do this through tags, i.e. docker run -it strapi:x.x. That way users will only get version bumps when they need them and this update method with symlinks won't impact production stability.

I'm a little unsure what the Dockerfile approach is for with the base image. It seems to be for putting Strapi into the same container as an custom app (https://github.com/strapi/strapi-docker#how-to-use-strapibase). Generally this wouldn't be good Docker practice, each should have it's own independent container and would communicate via ports. A production image like the above would be a preferred option.

maggie44 avatar Feb 10 '21 00:02 maggie44

you can use the following for production image built on top of strapi/base

FROM strapi/base
ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /srv/app && cp -a /tmp/node_modules /srv/app/
WORKDIR /srv/app
ADD . /srv/app
RUN npm run build
ENTRYPOINT npm run start
EXPOSE 1337

package.json has the script

"start": "NODE_ENV=production strapi start",

negati-ve avatar Apr 10 '21 16:04 negati-ve

It seems like that would be a way to run it in Docker in production, but not what I had in mind when I said a docker production image. By docker production image, I mean one that maintains the app inside, so when you do a Docker Pull you are brought up to date. And then only the config files exist outside. Same as we would see for common containers like Redis, Python, MariaDB and so forth. And with Node apps, like the guys have done over at LinuxServer, or the Directus guys: https://docs.directus.io/guides/installation/docker/

maggie44 avatar Apr 10 '21 17:04 maggie44

+1 to @maggie0002 , I want to docker run just start the server, and i do not want to wait npm install so long time. This is the magic of the docker image.

If I have to put all files in my host, I have no need to use the docker image, just use the command line to install strapi.

Can you please bundle the node_modules and other files in docker image, and only put the configs in docker volumes which we can mount via docker?

wyntau avatar Apr 22 '21 14:04 wyntau

FROM node:14-alpine

COPY . . RUN yarn install

ENV NODE_ENV production

EXPOSE 1337

CMD ["yarn", "start"]

erald14 avatar Jun 25 '21 08:06 erald14