简体   繁体   中英

Dockerize meteor application

I have a meteor application.This app works well on the Centos7 VM .
I need to create docker container of this app and install or import this container on other virtual machines.
What do ِdocker file need to save and load container on another VM ?
NodeJs ?
Mongodb ?
MeteorJs ?

Shouldn't I store Mongodb file in Docker container?

this is my docker file:

# Pull base image.
FROM node:8.11.4
# Install build tools to compile native npm modules
RUN npm install -g node-gyp
RUN apt-get install curl -y
RUN curl https://install.meteor.com/ | sh
# Create app directory
RUN mkdir -p /usr/app
COPY . /usr/app
RUN cd /usr/app/programs/server
RUN npm install
WORKDIR /usr/app
CMD ["node", "main.js"]
EXPOSE 3000

There are many ways to skin this cat ... lets assume you have researched the alternatives on how to execute a meteor app using containers by using tools which automates the below setup - meteor calls their version of this automation Galaxy

I suggest you run the meteor commands outside the container intended to run your app from since a meteor install is huge, slow to install and some of the libraries you may pull in, or the libraries your libraries pull in, may need c or c++ compilers so meteor and its friends do not need to get installed into your app container everytime you want to recompile your app ... your app container only needs nodejs and your bundle ... when you execute a meteor app it does not use meteor instead the app is executed using nodejs directly since at this point your code has been compiled into a bundle which is pure nodejs

Yes you would do well to put mongodb into its own container

No, no need to put MeteorJs inside your app container instead just like meteor itself those compile time tools are not needed during execution time so install MeteorJs as well as all other tools needed for a successful meteor build on your host machine which is where you execute your meteor build command

In your above Dockerfile the last statement EXPOSE 3000 will never get reached so put it before your CMD node

So outside your container get meteor installed then issue

cd /your/webapp/src
meteor build --server https://example.com  --verbose  --directory /webapp --server-only 

above will compile your meteor project into a bundle dir living at

ls -la /webapp/bundle/

then copy into that freshly cut bundle dir your Dockerfile etc :

.bashrc
Dockerfile
bundle/

then create your container

docker build --tag localhost:5000/hygge/loudweb-admin --no-cache . 
docker push localhost:5000/hygge/loudweb-admin

here is a stripped down Dockerfile

cat Dockerfile

#  normal mode - raw ubuntu run has finished and base image exists so run in epoc mode

FROM ubuntu:18.04

ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux

ENV NODE_VER=v8.11.4
ENV NODE_NAME=node-${NODE_VER}
ENV OS_ARCH=linux-x64
ENV COMSUFFIX=tar.gz

ENV NODE_PARENT=/${NODE_NAME}-${OS_ARCH}
ENV PATH=${NODE_PARENT}/bin:${PATH}
ENV NODE_PATH=${NODE_PARENT}/lib/node_modules

RUN apt-get update && apt-get install -y wget   && \
    wget -q https://nodejs.org/download/release/${NODE_VER}/${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} && \
    tar -xf ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}

ENV MONGO_URL='mongodb://$MONGO_SERVICE_HOST:$MONGO_SERVICE_PORT/meteor'
ENV ROOT_URL=https://example.com

ENV PORT 3000
EXPOSE 3000

RUN which node

WORKDIR /tmp

# CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf" ]
#  I strongly suggest you wrap below using supervisord
CMD ["node", "main.js"]

to launch your container issue

docker-compose -f /devopsmicro/docker-compose.yml pull loudmail  loud-devops  nodejs-enduser
docker-compose -f /devopsmicro/docker-compose.yml up -d 

here is a stripped down docker compose yaml file

version: '3'
services:

  nodejs-enduser:
    image: ${GKE_APP_IMAGE_ENDUSER}
    container_name: loud_enduser
    restart: always
    depends_on:
      - nodejs-admin
      - loudmongo
      - loudmail
    volumes:
      - /cryptdata6/var/log/loudlog-enduser:/loudlog-enduser
      - ${TMPDIR_GRAND_PARENT}/curr/loud-build/${PROJECT_ID}/webapp/enduser/bundle:/tmp
    environment:
      - MONGO_SERVICE_HOST=loudmongo
      - MONGO_SERVICE_PORT=$GKE_MONGO_PORT
      - MONGO_URL=mongodb://loudmongo:$GKE_MONGO_PORT/test
      - METEOR_SETTINGS=${METEOR_SETTINGS}
      - MAIL_URL=smtp://support@${GKE_DOMAIN_NAME}:blah@loudmail:587/
    links:
      - loudmongo
      - loudmail
    ports:
     - 127.0.0.1:3000:3000
    working_dir: /tmp
    command: /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

Once you have your app executing using containers you can work to stop using ubuntu as your container base and use a smaller, simpler docker base image like nodejs, busybox, etc however using ubuntu is easier initially since it has ability to let you install packages from inside a running container which is nice during development

the machinations surrounding above are vast ... above is a quick copy N paste plucked from the devops side of the house with hundreds of helper binaries + scripts, config templates, tls certs ... this is a tiny glimpse into the world of getting an app to execute

@Scott Stensland answer is good, in that it explains how to manually create a docker container for Meteor.

There is a simpler way use Meteor-up (mup) http://meteor-up.com/

EASILY DEPLOY YOUR APP

Meteor Up is a production quality Meteor app deployment tool.

Install with one command:

$ npm install --global mup

You set up a simple config file, and it looks after creating the container, doing npm install, setting up ssl certs etc. Much less work than doing it by hand

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM