Skip to content

Instantly share code, notes, and snippets.

@mapk0y
Last active October 8, 2016 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapk0y/a953fb928f2bd8660dc159ef3eb987ab to your computer and use it in GitHub Desktop.
Save mapk0y/a953fb928f2bd8660dc159ef3eb987ab to your computer and use it in GitHub Desktop.
docker の -v でファイルをマウントした時の見え方例

sample

$ # ホストに empty とだけかかれた .bashrc を用意
$ cat .bashrc
# empty

$ # 単純にコンテナにある /root/.bashrc を表示
$ docker run -it --rm debian cat /root/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

$ # ホストの empty と書かれた .bashrc をコンテナに -v でマウントして、元のファイルの代わりに見えるかを確認
$ docker run -it --rm -v ${PWD}/.bashrc:/root/.bashrc debian cat /root/.bashrc
# empty

注意事項

ファイルのリネームなどを伴う編集作業(inode が変わるもの、例として vim の backup+backupcopy no や sed)をすると見えるファイルがホストとコンテナ内で異なってしまう。これは、どちら側で行っても発生するので注意が必要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment