Docker volume command line option mistaking files

2019-07-24 19:00发布

I have the following command:

docker run --privileged=true -it --rm \
   -w /usr/src/app \
   -v ./package.json:/usr/src/app/package.json  \
   -v .bowerrc:/usr/src/app/.bowerrc \
   -v ./bower.json:/usr/src/app/bower.json  \
   -v ./build/npm.tmp/node_modules:/usr/src/app/build/npm.tmp/node_modules  \
   -v ./build/npm.tmp/bignibou-client/src/bower_components:/usr/src/app/build/npm.tmp/bignibou-client/src/bower_components \
   digitallyseamless/nodejs-bower-grunt bash

I end up with package.json being a directory in the docker container instead of a file.

root@c706711a7ad4:/usr/src/app# cat package.json/
cat: package.json/: Is a directory

How can I sort this problem? What am I getting wrong with the syntax?

edit:

Using the advice from @manojlds works fine:

Changing to -v $(pwd)/package.json:/usr/src/app/package.json \

sorts out the issue.

标签: docker
2条回答
我只想做你的唯一
2楼-- · 2019-07-24 19:56

Try providing an absolute path, instead of a relative path:

-v /home/projects/package.json:/user/src/app/package.json
查看更多
3楼-- · 2019-07-24 19:56

It looks like the Dockerfile in the digitallyseamless/nodejs-bower-grunt repo already does most of what you're trying to do:

  1. WORKDIR /usr/src/app - Set the workspace
  2. ONBUILD COPY package.json /usr/src/app/ - Copy the package.json file into the container.
  3. ONBUILD COPY bower.json .bowerrc* /usr/src/app/ - Copy the bower.json into the container.
  4. ONBUILD RUN bower install - Install bower

If you are lucky, you might be able to just do $ docker run -it --rm digitallyseamless/nodejs-bower-grunt, (or $ docker run -it --rm digitallyseamless/nodejs-bower-grunt bower for bower), and it will work.

查看更多
登录 后发表回答