web-dev-qa-db-ja.com

WindowsからBoot2docker VMにファイルを共有する最良の方法は何ですか?

Windowsでコードの準備を整えましたが、boot2dockerで共有するのは簡単ではありません。

また、boot2dockerが変更を永続化できないこともわかりました。たとえば、boot2dockerを再起動した後、/tempというフォルダーを作成します。このフォルダーは消え、非常に不便です。

Windowsにコードがありますが、それらをドッキングする必要がある場合の方法は何ですか?

- -更新 - -

VirtualBoxの設定を更新してboot2dockerを再起動しようとしましたが、マシン上で機能していません。

Enter image description here

 docker @ boot2docker:/ $ ls -al /c
total 4 
 drwxr-xr-x 3 root root 60 Jun 17 05:42 ./
drwxrwxr -x 17 root root 400 Jun 17 05:42 ../
dr-xr-xr-x 1 Docker staff 4096 Jun 16 09:47 Users /
31
yuyue007

Boot2Dockerは小さなLinux VM VirtualBoxで実行されています。そのため、このVMで実行されているDockerでファイルを(Windowsから)使用する前に、まずBoot2Dockerとコードを共有する必要がありますVM自体。

そのためには、mount WindowsフォルダーをVMシャットダウン時(ここではVM name of defaultが想定されます):

C:/Program Files/Oracle/VirtualBox/VBoxManage sharedfolder \
add default -name win_share -hostpath c:/work

(または、VirtualBox UIを開いて、フォルダをVMスクリーンショットで行ったのと同じように!)にマウントすることもできます)

sshをBoot2DockerにVM Dockerクイックスタートターミナルの場合:

docker-machine ssh default

次に、マウントを実行します。

  1. VM内にフォルダーを作成します:Sudo mkdir /VM_share
  2. Windowsフォルダーをマウントします:Sudo mount -t vboxsf win_share /VM_share

その後、Boot2Docker VM内でC:/workにアクセスできます。

cd /VM_share

コードがVM内に存在するようになったので、コンテナにボリュームとしてマウントすることで、Dockerで使用できます。

docker-machine ssh default
docker run --volume /VM_share:/folder/in/container some/image

または、Dockerイメージの構築中に使用することにより:

...
ADD /my_windows_folder /folder
...

63
Thomas Uhrig

こちらをご覧ください answer

Dockerツールボックス1.12.2およびVirtualBox 5.1.6を備えたWindows 10 Homeエディションがあります。

C:\Usersなどの追加の手順を実行せずに、コンテナのdocker-machine ssh defaultの下にフォルダを正常にマウントできました。

例:

docker run -it --rm -v /c/Users/antonyj/Documents/code:/mnt ubuntu /bin/bash

したがって、ファイルをC:\Usersの下に置くことは、おそらく最も簡単なことです。

ファイルをC:\Usersの下に置きたくない場合は、 受け入れられた回答 の手順に従う必要があります。

8
Antony

Linuxホスト(vm名 'default')で共有フォルダーWindowsゲストをマウントします。

「デフォルト」VMをシャットダウンします。

cd "C:\Program Files\Oracle\VirtualBox"
VBoxManage controlvm default poweroff

共有フォルダーのコマンドラインを追加します。

./VBoxManage sharedfolder add default -name win_share -hostpath "C:\docker\volumes"

Start VM(ヘッドレスのみのコマンドラインインターフェース):

/VBoxManage startvm headless  default

Sshに接続します。

docker-machine ssh default

作成VM sharedfolderディレクトリ:

Sudo mkdir /sharedcontent

WindowsフォルダーをホストVMにマウントします。

Sudo mount -t vboxsf win_share /sharedcontent
1
syphax

Docker Toolboxを使用すると、共有ディレクトリはonly/c/User

無効なディレクトリ。ボリュームディレクトリはユーザーディレクトリの下にある必要があります

ここに画像の説明を入力

Step1およびStep2の実装の「Dockerクイックスタートターミナル」のStep1&Step2コマンドは次のとおりです。

# Step 1. VirtualBox. Add the error in the command line, in the VirtualBox image interface manually add, as shown above.
"C:/Program Files/Oracle/VirtualBox/VBoxManage.exe" sharedfolder add default --name "E_DRIVE" --hostpath "e:\\" --automount

# Try 1. Only a temporary effect. Restart VM after sharing failure.
#docker-machine ssh default "Sudo mkdir -p /e" # Create a directory identifier, consistent with the Windows drive letter
#docker-machine ssh default "Sudo mount -t vboxsf -o uid=1000,gid=50 E_DRIVE /e"

# Try 2. Modify /etc/fstab. Do not use the permanent mount. Each restart /etc/fstab content will be reset
#docker-machine ssh default "Sudo sed -i '$ a\E_DRIVE /e vboxsf uid=1000,gid=50 0 0' /etc/fstab"

# Step 2. `C:\Program Files\Docker Toolbox\start.sh` https://github.com/docker/machine/issues/1814#issuecomment-239957893
docker-machine ssh default "cat <<EOF | Sudo tee /var/lib/boot2docker/bootlocal.sh && Sudo chmod u+x /var/lib/boot2docker/bootlocal.sh
#!/bin/sh
mkdir -p /e
mount -t vboxsf -o uid=1000,gid=50 E_DRIVE /e
EOF
"

次に、VMを再起動します。これを試して: docker run --name php-fpm --rm -it -v /e:/var/www/html php:7.1.4-fpm /bin/bash

参照:

1
王江奥

システムトレイでは、かわいいDockerクジラが泳いでいるはずです。右クリックして[設定]を選択します。

Enter image description here

クリック Apply。これにより、[資格情報]ダイアログが表示され、現在のWindows資格情報を提供する必要があります。正しく指定してください。また、管理者である必要があると思われます。

ホストディレクトリ(C:\ data)をコンテナにマウントするには、コンテナの実行中に-v(ボリューム)フラグを使用します。サンプルの実行を次に示します。

Enter image description here

ローカルDockerコンテナーにCentOSがあります。

docker run -v c:/data:/data **centos** ls /data
1
Kumar Abhishek