Dockerizing Meteor app

Hi!
I’m stuck trying to dockerize our app.

Dockerfile

FROM node:14.21.1

WORKDIR /usr/src/app

RUN curl https://install.meteor.com/ | sh

COPY . .

ENV METEOR_ALLOW_SUPERUSER=true

RUN meteor npm install --production

RUN meteor build --server-only --allow-superuser --directory ../build --architecture os.linux.x86_64

WORKDIR /usr/src/build/bundle/programs/server

RUN npm install

WORKDIR /usr/src/build/bundle

EXPOSE 3000

CMD ["node", "main.js"]
docker buildx build -t my-meteor-app .

Build goes smoothly except for this message:

Even with METEOR_ALLOW_SUPERUSER or --allow-superuser, permissions in your app
directory will be incorrect if you ever attempt to perform any Meteor tasks as
a normal user. If you need to fix your permissions, run the following command
from the root of your project:

sudo chown -Rh .meteor/local

Running image:
docker run -e ROOT_URL=http://localhost:3000/ -e MONGO_URL="..." -e METEOR_SETTINGS="..." -e PORT=3000 -p 3000:3000 my-meteor-app:latest

Logs:

2024-05-29 12:14:47 creating apollo server
2024-05-29 12:14:47 apollo server started

So the app is somewhat working, but when I go to localhost:3000 there is just ERR_CONNECTION_REFUSED

What am I doing wrong here? Any help is appreciated!

When I run the dockerfile to reproduce, I don’t get past:

RUN meteor build --server-only --allow-superuser --directory ../build --architecture os.linux.x86_64

I get error:

ERROR: failed to solve: process “/bin/sh -c meteor build --server-only --allow-superuser --directory …/build --architecture os.linux.x86_64” did not complete successfully: exit code: 1

and

2.810 build: You’re not in a Meteor project directory.

I suspect the Dockerfile is missing some additional information that allows full reproduction of your issue. If you add those, I can try again to see.

Just for fun, what do you see regarding your mapped ports when you run docker ps?

Have you tried setting up a non-root user?

This is what I see

Sending build context to Docker daemon  7.713MB
Step 1/12 : FROM node:14.21.1
 ---> c08c80352dd3
Step 2/12 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 54f4dc999c66
Step 3/12 : RUN curl https://install.meteor.com/ | sh
 ---> Using cache
 ---> dadb507c232b
Step 4/12 : COPY . .
 ---> 8f782cedddad
Step 5/12 : ENV METEOR_ALLOW_SUPERUSER=true
 ---> Running in 90e2ae911d98
 ---> Removed intermediate container 90e2ae911d98
 ---> 2fcca205fcba
Step 6/12 : RUN meteor npm install --production
 ---> Running in 87fc0199bbed

> @apollo/protobufjs@1.2.7 postinstall /usr/src/app/node_modules/@apollo/protobufjs
> node scripts/postinstall

added 839 packages from 572 contributors in 57.406s

154 packages are looking for funding
  run `npm fund` for details

 ---> Removed intermediate container 87fc0199bbed
 ---> 245cc1a93ab4
Step 7/12 : RUN meteor build --server-only --allow-superuser --directory ../build --architecture os.linux.x86_64
 ---> Running in aacf1886821a

Even with METEOR_ALLOW_SUPERUSER or --allow-superuser, permissions in your app
directory will be incorrect if you ever attempt to perform any Meteor tasks as
a normal user. If you need to fix your permissions, run the following command
from the root of your project:

  sudo chown -Rh <username> .meteor/local


Even with METEOR_ALLOW_SUPERUSER or --allow-superuser, permissions in your app
directory will be incorrect if you ever attempt to perform any Meteor tasks as
a normal user. If you need to fix your permissions, run the following command
from the root of your project:

  sudo chown -Rh <username> .meteor/local

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
 ---> Removed intermediate container aacf1886821a
 ---> 8dd50b97bb3e
Step 8/12 : WORKDIR /usr/src/build/bundle/programs/server
 ---> Running in e51c323e96d2
 ---> Removed intermediate container e51c323e96d2
 ---> 0f4c793914ce
Step 9/12 : RUN npm install
 ---> Running in 6000b009841d
npm WARN deprecated node-pre-gyp@0.15.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm WARN deprecated npmlog@4.1.2: This package is no longer supported.
npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated osenv@0.1.5: This package is no longer supported.
npm WARN deprecated gauge@2.7.4: This package is no longer supported.
npm WARN deprecated are-we-there-yet@1.1.7: This package is no longer supported.
npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs

> fibers@5.0.1 install /usr/src/build/bundle/programs/server/node_modules/fibers
> node build.js || nodejs build.js

`linux-x64-83-glibc` exists; testing
Binary is fine; exiting
npm WARN lifecycle meteor-dev-bundle@~install: cannot run in wd meteor-dev-bundle@ node npm-rebuild.js (wd=/usr/src/build/bundle/programs/server)
added 155 packages from 87 contributors and audited 156 packages in 8.476s

7 packages are looking for funding
  run `npm fund` for details

found 1 moderate severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
 ---> Removed intermediate container 6000b009841d
 ---> 173c82e57e96
Step 10/12 : WORKDIR /usr/src/build/bundle
 ---> Running in 63b1385a1b83
 ---> Removed intermediate container 63b1385a1b83
 ---> 2e81b8fb5df2
Step 11/12 : EXPOSE 3000
 ---> Running in 0a21ca1980a0
 ---> Removed intermediate container 0a21ca1980a0
 ---> 56e3852761ee
Step 12/12 : CMD ["node", "main.js"]
 ---> Running in fdcff1ac0a55
 ---> Removed intermediate container fdcff1ac0a55
 ---> ac7d03a13bc9
Successfully built ac7d03a13bc9
Successfully tagged my-meteor-app:latest


docker ps

 my-meteor-app:latest   "docker-entrypoint.s…"   31 seconds ago   Up 30 seconds   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   

Maybe I should try again. Do you have a suggestion how to do it? I am docker newb obviously.

You can see how meteor-up does it.

Also on a side note, copying package.json and lock files → npm install → full copy, will be significantly faster for multiple deploys as it will cache the npm install step as long as your package jsons are not changed. Super helpful while testing multiple times.

@impedingdoom you can check out GitHub - zodern/meteor-docker: Docker image for Meteor.

Root image:

Non-root user image:

Docker example, how it’s done at Meteor 2 based WeKan Open Source kanban https://wekan.github.io :

1 Like