Very new to Docker so please excuse what is likely a basic question. I am trying to understand at which point the node modules are installed if I have a run npm install command in my Dockerfile such as:
# Create our app directory.
RUN mkdir -p /usr/app
# Install dependancies.
COPY package.json /usr/app/
RUN npm install
COPY . /usr/app
# Start the app.
CMD [ "npm", "start" ]
Is this at the time the image is built? If so how are native node modules handled (e.g. bcrypt) if I run this image as a container on a different machine e.g. build the image on a Mac and then run a container on an EC2 instance?
I feel I have probably missed a very simple concept so any help would be greatly appreciated!
Yes, and more specifically when the
RUN npm install command executes.
If you’re running Docker on a Mac, there is an intermediate Linux virtual machine that you may or may not see, but it is always a Linux image. The userspace is also fixed (it’s whatever Linux distribution the
node:8.4.0 base image starts from).
docker push the image to a registry, then it pushes the binary contents of the image, and so when you
docker pull or
docker run the image on an EC2 instance, it pulls that same binary back down. If you’re repeating the
docker build from source on the target machine, then it will repeat the same installation steps (on the same base operating system and the same base userspace) and it should get out a near-identical installation.
Brilliant! Thanks, I’ve been trying to cram too many concepts into my head too quickly and your simple description just gave me my light bulb moment!!