How to access lower layer files in docker?

107 views Asked by At

I have two docker images, one provides files from a directory outside the services directory, and the other that service itself. So let image1 be the one for outside files and let image2 be the one containing the service.

image1's dockerfile is as follows:

FROM node:0.10.38
ADD . /opt/services/models
WORKDIR /opt/services/models
RUN npm install
VOLUME /opt/services/models
CMD ["node"]

image2's dockerfile is as follows:

FROM 127.0.0.1:5000/models:latest
ADD . /opt/serivces/app
WORKDIR /opt/serivces/app
RUN npm install
EXPOSE 9001
ENTRYPOINT ["node", "app.js"]

I am trying to have it so image2 can require the modules from image1 however /opt/services/models does not seem to exist within image2. I have these containers run with kubernetes, which I specify the volume image2 is to mount. Is there something I'm missing or can I just no access image1's files?

EDIT 1

Oddly enough, when I created an image3, which is almost identical to image2, except it is adding a different directory, the directory from image1 is present regardless of whether I specify the volume.

EDIT 2

I haven't actually found a solution to this, but I have found a workaround of having all Dockerfiles in the root of the project and adding any needed directory (this isn't great but it works). The only thing I have to do differently is docker build -t 127.0.0.1:5000/imageX --file=./imageXDockerfile . so that I can specify which image to build.

0

There are 0 answers