300D7309EF17
300D7309EF17

Reputation: 24653

installing Node modules on Docker: why are they disappearing?

I'm trying to create my first node Docker image. It's for a hubot. Here's the basics of the Dockerfile:

FROM ubuntu:14.04
VOLUME /opt
COPY package.json /opt/hubot/
RUN apt-get update && apt-get -y install build-essential nodejs python
RUN npm install -g npm
WORKDIR /opt/hubot/
RUN npm install --prefix /opt/hubot/
COPY app /opt/hubot/app

The problem is that the node_modules don't exist after the build step is over. I can see that it is being placed in my expected location during the build step:

make[1]: Entering directory `/opt/hubot/node_modules/aws2js/node_modules/mime-magic'

So, I know Docker files are somewhat stateless, which is why "apt update && install" is necessary. But something gets left behind, otherwise the installed apt bits wouldn't be there at the end. How can I persist the node_modules?

Upvotes: 0

Views: 841

Answers (1)

user2105103
user2105103

Reputation: 13135

Changes made to VOLUMEs do not persist.

Data Volumes

A data volume is a specially-designated directory within one or more containers that bypasses the Union File System to provide several useful features for persistent or shared data:

Data volumes can be shared and reused between containers

Changes to a data volume are made directly

Changes to a data volume will not be included when you update an image

Volumes persist until no containers use them

Upvotes: 3

Related Questions