Reputation: 7535
I'm trying to work on a ReactJS project for development purposes in Docker, and this project will be shared across a team.
However, I'm having trouble understanding how this works because I want to volume share my app
directory into the container, but it seems I have to copy package.json
into the container to npm install
and therefore run nom run start
my directory structure is:
app/
src/
public/
node_modules/
package.json
docker/
admin/
dockerfile
docker-compose.yml
dockerfile
FROM node:7.8.0
WORKDIR /app
RUN npm install
EXPOSE 3000
CMD npm run start
docker-compose.yml
version: '3'
services:
admin:
build:
context: ./docker/admin
dockerfile: dockerfile
image: project/admin
volumes:
- ./app:/app
ports:
- "3000:3000"
So the problem is: when the dockerfile runs, npm install
fails because the volume sharing from the docker-compose
hasn't happened yet, so it thinks there's no package.json
. So it sounds like I have to copy package.json
into the container, which isn't ideal for development as far as making changes.
Furthermore, I believe you can only COPY
files into the container from within the same directory as the dockerfile, which would mean I'd have to move the dockerfile to the root of the project. I don't love this idea because I'll have other containers in this project as well, and they'll need dockerfiles too.
Is there better solution for handling Node development from within Docker? Essentially, I'm looking to make the "up and running" process as simple as possible for other devs on the team.
Upvotes: 1
Views: 780
Reputation: 5519
During development you need:
If you will try put you files to Docker container during development, you will have overhead on development process. You computer and developer will spend more time, then with native usage node.js
That why wrapping Node.js in Docker during development is bad practice.
When you need Docker during development?
docker-compose
is the best solution rights now.Dockerfile
+ .dockerignore
will describe how make your artifactUpvotes: 1