docker COPY all fails when not in C drive

谁说胖子不能爱 提交于 2020-01-25 08:53:06

问题


NOTE: I'm on windows 10, using docker-machine / virtual box

I have a project which builds and runs just fine when on my C:\ drive.

If I copy all files to my second hard drive F:\ the COPY . /path command in my Dockerfile appears to succeed, however when I inspect that directory in the container it's empty.

My docker file;

FROM php:7.3-apache-stretch

RUN docker-php-ext-install pdo_mysql \
    && a2enmod rewrite negotiation

COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/apache/vhost.conf /etc/apache2/sites-available/000-default.conf
COPY . /srv/app

WORKDIR /srv/app

My docker-compose.yml file;

version: '3'
services:
  app:
    build: .
    ports:
      - 8080:80
    volumes:
      - .:/srv/app

The odd thing here is that the first two COPY commands work

COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/apache/vhost.conf /etc/apache2/sites-available/000-default.conf

I can navigate to those two directories and see the two files individually with the right content. Some resources suggest the container does not have access to my second drive, but it clearly does, else these files would also not work.

FYI I'm using the following to build and then inspect the container

docker-machine up -d --build
docker-machine exec app bash
ls

UPDATE If I change the copy folder to /var/www/html the command works properly. I'm currently only putting the files in /srv/app because I've been following tutorial. I'm not aware of the advantage/disadvantage of this at this stage.


SOLUTION Thanks to @LinPy I used this comment to help me get the right setting: https://github.com/docker/machine/issues/3908#issuecomment-412385611

I opened a command prompt in C:\Program Files\Oracle\VirtualBox and ran the following command.

VBoxManage.exe sharedfolder add default --name "/f" --hostpath "f:\\" --automount

My VirtualBox settings now looks like this;


回答1:


try this :

docker-machine stop

vboxmanage sharedfolder add default --name "project_name" --hostpath "<full_project_path>" --automount

docker-machine start 

then configure the mount

volumes:
  - /project_name:/path/in/container/project_name

when that did not help, try this:

docker-machine create -d virtualbox --virtualbox-share-folder "\\?\f:\paht1\path2:installdir" test2

you can see also this issue



来源:https://stackoverflow.com/questions/57476559/docker-copy-all-fails-when-not-in-c-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!