Open rogierslag opened 6 years ago
would love to see this
It is quite similar to the one we internally use for our maily setup
FROM node:8.5
MAINTAINER inventid
EXPOSE 3000
RUN mkdir -p /usr/src/app/src
RUN groupadd -r maily && useradd -r -g maily -d /usr/src/app maily
RUN chown maily:maily /usr/src/app
RUN npm install babel-cli babel-preset-es2015 babel-preset-react -g
USER maily
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY index.js /usr/src/app/src/
COPY .babelrc /usr/src/app/src/
COPY components /usr/src/app/src/components
RUN cd /usr/src/app/src && babel . --out-dir ../
CMD [ "node", "index.js" ]
Note that that project does not use a complete webpack build, so instead we compile some files directly using babel
during the Docker build
Thanks! I actually ended up writing my own yesterday, I will share that as well in case anyone stumbles across this.
Dockerfile
FROM node:8.11.1 as builder
# copy project to docker
COPY package.json package.json
COPY .babelrc .babelrc
COPY yarn.lock yarn.lock
# Create production build
RUN yarn install --frozen-lockfile
COPY . .
RUN NODE_ENV=production yarn build
FROM node:8.11.1
COPY --from=builder /dist /dist
COPY --from=builder /node_modules /node_modules
CMD NODE_ENV=production node dist/index.js
EXPOSE 3000
docker-compose.yml
version: '3'
services:
server:
build:
context: .
dockerfile: ./docker/Dockerfile
ports:
- 3000:3000
volumes:
- ./src:/src
package.json
"scripts": {
"build": "babel src --out-dir dist --copy-files",
"start": "yarn build && node dist/index.js"
},
"dependencies": {
"@react-pdf/core": "^0.7.6",
"@react-pdf/node": "^0.7.6",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"babel-polyfill": "^6.26.0",
"body-parser": "^1.18.2",
"express": "^4.16.2",
"uuid-v4": "^0.1.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1"
}
Add our default example dockerfile