LoginSignup
6
7

More than 5 years have passed since last update.

docker execコマンドでHostからGuestへのファイル転送をする

Last updated at Posted at 2015-01-06

背景

sshd等を使わずに、Dockerコンテナ上でtest-kitchenを実行したい等の理由から、
これを作ったことによって得た知見。

ちなみに逆(Guest→Host)はdocker cpコマンドで正式にサポートされている。

前提

  • Docker 1.3 or later
  • tar (GNU Tar) ※Host, Guest両方

方法

docker execコマンドを利用してファイル転送を実現する。

簡単な説明

目的のファイル(or ディレクトリ)をtarで固めて、
それを標準入力に流し、docker execにパイプで繋いでコンテナ上で展開させる。

実際のコマンド例

cd /path/to/host/target && tar cf - ./ | docker exec -i container_id tar x -C /path/to/guest/target

もう少しスマートな書き方ありそう…w

所感

  • docker execを運用で使ったら負け感あるけど、あるとだいぶ便利
  • たぶんtarじゃなくてもできる方法は色々ある(特に単体のファイル転送とか)
6
7
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7