strapi-community / strapi-tool-dockerize

Easy add support for docker to your strapi project
MIT License
558 stars 35 forks source link

Fixed bind mount paths #30

Closed nevotheless closed 2 years ago

nevotheless commented 2 years ago

I right now ran into this and didn't get why the container didn't write back the changes to the host files. Turns out the bind mount path were wrong and were pointing into /opt/app instead of /app.

Eventyret commented 2 years ago

I think this might be wrong @nevotheless 🤷‍♀️ or am I reading it the wrong way ? Thank you again for opening a PR. https://github.com/strapi-community/strapi-tool-dockerize/blob/main/templates/Dockerfile.liquid#L26

We are looking inside for /opt/app not /app

nevotheless commented 2 years ago

That's weird, the generated Dockerfile i got looks like this


FROM node:16-alpine as build
# Installing libvips-dev for sharp Compatability
RUN apk update && apk add build-base gcc autoconf automake zlib-dev libpng-dev vips-dev && rm -rf /var/cache/apk/* > /dev/null 2>&1
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build

FROM node:16-alpine
RUN apk add vips-dev
RUN rm -rf /var/cache/apk/*
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app
COPY --from=build /opt/node_modules ./node_modules
ENV PATH /opt/node_modules/.bin:$PATH
COPY --from=build /opt/app ./
EXPOSE 1337
CMD ["yarn", "develop"] // i changed this to develop for the time being
nevotheless commented 2 years ago

Yeah to verify i just ran

npx @strapi-community/dockerize new --dbclient=mysql --dbhost=localhost --dbport=1234 --dbname=strapi --dbusername=strapi --dbpassword=strapi --projecttype=js --packagemanager=yarn --usecompose=true --env=both

in an empty directory the outcome was this Dockerfile

image
Eventyret commented 2 years ago

So the file is incomplete it looks correct ? Workdir is set to /opt/app Try ssh into the container and look what it shows you as paths ?

nevotheless commented 2 years ago

But WORKDIR is only set in the builder stage not in the actual "final" stage. When i get into the container the immediate directory is /app like it is stated in the final stage.

https://github.com/strapi-community/strapi-tool-dockerize/blob/main/templates/Dockerfile-prod.liquid this file seems to be used for the command hence the /app directory i assume.

Eventyret commented 2 years ago

I'll check it out then because then we rather want to fix the final stage. Else it would break the rest.

If you care to check or fix the final stage then I bee happy to merge it.

nevotheless commented 2 years ago

Yeah i can check it out and fix it. Just need to find out how to use the generator shenanigans locally without using npx @strapi-community/dockerize.

Eventyret commented 2 years ago

Yeah i can check it out and fix it. Just need to find out how to use the generator shenanigans locally without using npx @strapi-community/dockerize.

Clone down the repo. then do npm link in it and you can use strapi-dockerize to test it locally :)

Thank you again.