2

I'm developing a webapp and I need node for my development environment.

I don't want a docker production container, but a development one: I need to share files between docker container and local development machines. I don't want to run docker each time I change a source file.

Currently my dockerfile is:

#React development
FROM node:4.1.1-wheezy 
MAINTAINER xxxxx
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -y install sudo locales apt-utils
RUN locale-gen es_ES.UTF-8
RUN dpkg-reconfigure locales
RUN echo Europe/Madrid | sudo tee /etc/timezone && sudo dpkg-reconfigure --frontend noninteractive tzdata
ADD src/package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /src && cp -a /tmp/node_modules /src/
WORKDIR /src
EXPOSE 3000
VOLUME /src

I need directory to put all my source files (share a directory via data volume). I also need to execute npm install in my dockerfile so I get my node_modules directory inside my sources directory (/src/node_modules).

However when I mount a host directory as a data volume, as /src dir already exists inside the container’s image, its contents will be replaced by the contents of /src directory on the host so I don't have my /src/node_modules directory anymore:

docker run -it  --volumes-from data-container --name node-dev user/dev-node /bin/bash

My host directory doesn't have node_modules directory because I get it through github and is not sync because it's quite a heavy dir.

3
  • Could you please clarify the question? I think I had a similar problem but it's a little hard to tell what you're asking Commented Sep 28, 2015 at 22:10
  • Code should be on local machine so I can update files using my code editor. Files updated should be replicated instantaneously to the container, so I need a data volume container mapped to the host. My node_modules folder is inside the source directory, but this directory is generated just inside the container (I need to execute npm install and node could not be installed on my dev machine, or a different version from the container). Commented Sep 29, 2015 at 6:07
  • Interesting, looks like you got it figured out below. I posted my own solution too just for the sake of variety. Commented Sep 29, 2015 at 14:29

2 Answers 2

1

My solution is to copy node_modules directory using an ENTRYPOINT directive.

docker-entrypoint.sh:

#!/bin/bash
if ! [ -d node_modules ]; then
        cp -a /tmp/node_modules /src/
fi
exec "$@"

2 lines added to dockerfile:

COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Sign up to request clarification or add additional context in comments.

1 Comment

I think this should have been the answer to begin with (as it's directly relevant to your question). Only thing I ask- could you somehow re-word the title of the question to reflect the question?
1

Disclaimer: the following has nothing to do with Docker specifically.

I use SSHFS. The Ubuntu Wiki has a pretty good description:

SSHFS is a tool that uses SSH to enable mounting of a remote filesystem on a local machine; the network is (mostly) transparent to the user.

Not sure if this is useful in your scenario, but all my hosts run a SSH server anyways so it was a no-brainer for me. The win-sshfs project doesn't seem to be actively developed anymore, but it still runs fine in win 8/10 (though the setup is a little weird). OS X and Linux both have better support for this through FUSE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.