Dockerfile problem,

Hello, I have been trying for almost 3 weeks to build and run a meteor app (bundle) using Docker, I have tried all the majors recommendations in Meteor forums, Stackoverflow and official documentarion with no success, first I tried to make the bundle and put inside the docker but have awful results, then I realized what I need to do is to make the bundle inside the docker and use a multistage Dockerfile, here is the one I am using right now:

FROM chneau/meteor:alpine as meteor
    
    USER 0
    RUN mkdir -p /build /app
    RUN chown 1000 -R /build /app
    WORKDIR /app
    COPY --chown=1000:1000 ./app .
    COPY --chown=1000:1000 ./app/packages.json ./packages/
    RUN rm -rf node_modules/*
    RUN rm -rf .meteor/local/*
    
    USER 1000
    RUN meteor update --packages-only
    RUN meteor npm ci
    RUN meteor build --architecture=os.linux.x86_64 --directory /build
    
    
    FROM node:lts-alpine as mid
    
    USER 0
    RUN apk add --no-cache python make g++
    RUN mkdir -p /app
    RUN chown 1000 -R /app
    WORKDIR /app
    COPY --chown=1000:1000 --from=meteor /build/bundle .
    
    USER 1000
    WORKDIR /app/programs/server
    RUN rm -rf node_modules
    RUN rm -f package-lock.json
    RUN npm i
    
    FROM node:lts-alpine
    
    USER 0
    ENV TZ=America/Santiago
    RUN apk add -U --no-cache tzdata && cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    RUN mkdir -p /app
    RUN chown 1000 -R /app
    WORKDIR /app
    COPY --chown=1000:1000 --from=mid /app .
    
    USER 1000
    ENV LC_ALL=C.UTF-8
    ENV ROOT_URL=http://localhost/
    ENV MONGO_URL=mongodb://locahost:21027/meteor
    ENV PORT=3000
    EXPOSE 3000
    ENTRYPOINT [ "/usr/local/bin/node", "/app/main.js" ]

if I build with docker build -t my-image:v1 . then run my app with docker run -d --env-file .dockerenv --publish 0.0.0.0:3000:3000 --name my-bundle my-image:v1 it exposes port:3000 but when I try to navigate with my browser to http://127.0.0.1:3000 it redirects to https://localhost, if i do docker exec -u 0 -it my-bundle sh, then apk add curl, then curl 127.0.0.1:3000 I can see the meteor app running inside docker.

Has anyone had this issue before, maybe I am missing some configuration? my bundle also works fine outside docker with node main.js in the bundle folder and can visit http://127.0.0.1:3000 with my browser.

Thanks in advance

You have to add the port to the ROOT_URL environment variable:
ENV ROOT_URL=http://localhost:3000

I think that should do the trick!

It worked on the simple todos app, but when I put my METEOR_SETTINGS in my real app, it broke again, I can see is something with my specific settings. Thanks a lot. This can be marked as solved now

1 Like

Hi

I had a similar problem with bundling and containerizing Meteor, but your work helped me make some progress.

At the moment the process keeps crashing at Step 11/41 : RUN meteor update --packages-only and the error reads

The command ‘/bin/sh -c meteor update --packages-only’ returned a non-zero code: 137

Did this happen to you (I’m using a meteor settings file as well).

Thanks
Don

hello, my error was unrelated, finally I had force-ssl as a dependency, so I just removed it and it worked, so I can tell you to remove any dependency that you are not using

I also changed my base image and now I am using
FROM geoffreybooth/meteor-base:2.5 as meteor