Meteor 3.x.x with Docker and Docker Compose
this builds it on the server which is not very effective for fast deployments but avoids having any complicated logic for building locally then pushing to server and delete the local deploy later.
- its nice how it adds a pretty powerful mongoDB install.
- Only uses NODE no specific images like ZODERN/METEOR
- env vars are automatically loaded by docker compose in the
docker-compose.yml
file when building
Launch with:
docker compose -f docker-compose.yml up --build
# Build stage
FROM node:22.13.1 as builder
# Install Meteor
RUN curl https://install.meteor.com/?release=3.1.2 | sh
# Set up directories and permissions
RUN mkdir /app /build && \
chown node:node /app /build
# Copy the Meteor application source and settings.json
COPY --chown=node:node . /app
WORKDIR /app
# Switch to non-root user
USER node
# Install dependencies
RUN meteor npm install
# Build the Meteor application
RUN meteor build --directory /build
# Runtime stage
# FROM zodern/meteor
FROM node:22.13.1
# Copy the built app from builder stage
COPY --from=builder --chown=app:app /build/bundle /built_app
# Copy settings.json from builder stage
COPY --from=builder --chown=app:app /app/settings.json /built_app/settings.json
# Install runtime dependencies
RUN cd /built_app/programs/server && npm install
# Set default environment variables
ENV PORT=3000 \
ROOT_URL=http://localhost:3000 \
MONGO_URL=mongodb://mongo:27017/yourapp \
NODE_ENV=production \
EXA_API_KEY=${EXA_API_KEY} \
OPENAI_API_KEY=${OPENAI_API_KEY} \
DEEP_SEEK_API_KEY=${DEEP_SEEK_API_KEY}
EXPOSE 3000
# Use the shell form of CMD to set METEOR_SETTINGS from the file and run the app.
CMD ["sh", "-c", "echo 'Setting METEOR_SETTINGS from /built_app/settings.json'; export METEOR_SETTINGS=\"$(cat /built_app/settings.json | tr -d '\\n')\"; echo 'METEOR_SETTINGS is:' $METEOR_SETTINGS; node /built_app/main.js"]
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- PORT=3000
- ROOT_URL=http://localhost:3000
- MONGO_URL=mongodb://mongo:27017/yourapp
- EXA_API_KEY=${EXA_API_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- DEEP_SEEK_API_KEY=${DEEP_SEEK_API_KEY}
depends_on:
- mongo
mongo:
image: mongo:latest
volumes:
- mongodb_data:/data/db
volumes:
mongodb_data:
Coolify
this worked for me in Coolify (https://coolify.io/docs/)
most important! Restart your PROXY after setting this up, if not HTTPS will likely not work
version: '3.8'
services:
app:
build: .
# ports:
# - "3000:3000"
environment:
- NODE_ENV=production
- ROOT_URL=${STOCKREPORT_URL}
- PORT=${STOCKREPORT_PORT}
- MONGO_URL=mongodb://mongo:27017/yourapp
- EXA_API_KEY=${EXA_API_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- DEEP_SEEK_API_KEY=${DEEP_SEEK_API_KEY}
depends_on:
- mongo
mongo:
image: mongo:latest
volumes:
- mongodb_data:/data/db
volumes:
mongodb_data:
STOCKREPORT_URL
and STOCKREPORT_PORT
are two env variables I set in the Coolify UI under the ENV variables section:
