Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build in Dockerfile #283

Open
shankie-codes opened this issue Jan 31, 2017 · 2 comments
Open

Build in Dockerfile #283

shankie-codes opened this issue Jan 31, 2017 · 2 comments
Labels
v3.0.0 CLI/devtools optimization/improvements
Milestone

Comments

@shankie-codes
Copy link

Is there any reason why that we don't do the build in the Dockerfile so that it gets built on docker-compose build rather than docker-compose up? By being in up, it effectively takes down your server every time you do a code push as there's a considerable wait for it to do the build inside the container. It also means that simple container restarts incur a build, even when you might not have pushed code.

In my project, I have changed the Dockerfile to:

FROM node:7
MAINTAINER jaga santagostino <kandros5591@gmail.com>

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app

ENV NODE_ENV production

# Build it
RUN npm run clean && npm run build && npm run build:server

EXPOSE 8000
CMD ["npm", "run", "start:prod"]

and added an additional volume map to docker-compose.yml to prevent volume-mapping the host's (blank) dist directory over top of what we've just built in the last step.

Regardez:

  volumes:
   - .:/usr/src/app/
   - /usr/src/app/node_modules
   - /usr/src/app/dist

Any reason for this? If not, I can do a PR as I think it's a much nicer workflow.

@mannyhenri
Copy link
Contributor

Will definitely look into this, thanks for sharing.

@mannyhenri mannyhenri added the v3.0.0 CLI/devtools optimization/improvements label Jun 2, 2018
@mannyhenri mannyhenri added this to To do in MERN Roadmap via automation Jun 2, 2018
@mannyhenri mannyhenri added this to the 3.0.0 milestone Jun 2, 2018
@mattlubner
Copy link
Contributor

Agreed, this is a common pattern these days and we'll definitely be moving towards it as we make our way through the v3 milestones.

Do be aware though, using persistent Docker volumes to exclude subdirectories from the host's (project's) working directory will have the side effects of slowing the container's startup (after each image rebuild) and resulting in (potentially many) orphaned persistent volumes (of previous versions of dist/ and node_modules/).

I'd recommend the (admittedly more tedious) alternative of explicitly volume-mapping each individual project file and directory. If anyone has a better way, please share!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3.0.0 CLI/devtools optimization/improvements
Projects
MERN Roadmap
  
To do
Development

No branches or pull requests

3 participants