LoginSignup
3

More than 5 years have passed since last update.

dockerコンテナ内に無理やりzshの設定を突っ込むメモ

Posted at

スマートな方法が思い付かなかったのでシェルスクリプトでラップするという雜な手段を取った。

#!/bin/zsh

set -e

container_name="container_app_1"

cp_to_container()
{
  if ! docker exec ${container_name} test -e $2; then
    docker cp -L $1 ${container_name}:$2
  fi
}

cp_to_container ~/.zshenv /root/.zshenv
cp_to_container ~/.oh-my-zsh /root/.oh-my-zsh
cp_to_container ~/.zsh /root/.zsh
cp_to_container ~/.zshrc /root/.zshrc
cp_to_container ~/.zshrc.github /root/.zshrc.github
cp_to_container ~/.zshrc.peco /root/.zshrc.peco
cp_to_container ~/.gitconfig /root/.gitconfig
cp_to_container ~/.gitconfig.local /root/.gitconfig.local
cp_to_container `which diff-highlight` /usr/bin/diff-highlight

if ! docker exec ${container_name} test -e /usr/bin/peco; then
  docker exec ${container_name} sh -c "curl -L -o /root/peco.tar.gz https://github.com/peco/peco/releases/download/v0.4.5/peco_linux_amd64.tar.gz && tar xf /root/peco.tar.gz -C /root && cp /root/peco_linux_amd64/peco /usr/bin/peco"
fi

docker exec -it ${container_name} sh -c "export TERM=${TERM}; exec zsh"

これで、手元のマシンと同じ様な感じで開発用コンテナを操作できる。
ホームディレクトリを丸ごとマウントするという手段も無くは無かったが、大げさ過ぎるし事故った時にヤバイので止めた。

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
3