My idea is to use docker container for building js and css assets separately from an app. I have code at the host machine and I'm trying to mount the directory with my code as volume to docker container. But in the Dockerfile when I do RUN npm install sematic-ui --save
it doesn't change anything in the directory I'm trying to mount.
Is the mounted volume available at all at the building process or should I install npm packages only when I run image?
Also what is the best practice in my case?
EDIT:
I simplified the case to show an example. Here are my files.
docker-compose.yml
version: '3'
services:
web:
build: .
volumes:
- ./vol:/root/test
Dockerfile
FROM debian:9
WORKDIR /root/test
RUN touch index.html
CMD /bin/sh
Then I do docker-compose build
. I expect to see the index.html in the vol
directory on the host. Why this doesn't happen? As I noticed some docker images could change the host's filesystem during build. But I couldn't.
When you mount a volume, it replaces everything in the directory to which you are mounting it in the container. Whatever you have in /root/test
will be replaced with your host ./vol
directory.
Also I'm not sure this would work anyway because when these lines happen:
WORKDIR /root/test
RUN touch index.html
the /root/test directory doesn't exist. I'm not sure where Docker is putting the index.html. Typically I will RUN mkdir -p /root/test
to ensure the container path is explicitly created.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.