Humanity

Edit the world by your favorite way

DockerコンテナをAutostartするDebian用のSysVinit scripts作った

追記

  • /etc/init.d/docker-autostart start時に「Error: Conflict, The name is already assigned to . You have to delete (or rename) that container to be able to assign to a container again.」といったエラーメッセージが出てコンテナが起動しない問題を修正

インストール方法とか

tyru/docker-initscripts · GitHub
インストール手順はinstall.shを見てください。もしくはrootで実行してください。

にそれぞれ置いて、/etc/default/docker-autostartに元々書いてあるサンプルを見ながら自分用に編集してください。

Debian用のSysVinit scriptsを作る時は

  1. /etc/init.d/skeleton からコピーしてきて
  2. LSBInitScripts - Debian Wikiを参考に先頭のコメントを編集して
    • 今回はRequired-Startにdocker入れるとかDefault-Stopは必要ないので空にするとか
  3. 必要なアクション(今回はstartのみ)を実装して完成

な感じです。

SystemdやUpstart用のAutostartスクリプト

は公式サイトにあるのですが、SysVinit用のがないので作りました。
Automatically starting containers - Docker Documentation

JessieではSystemdになるし近い内にお払い箱になるかも…

LXC単体で使う場合のAutostart

lxc-toolsでOSブート時にLXCを起動 - Humanity
以前こんなの書いたけど、libvirtでautostartできるって話を聞いた気がするので、出来るならそっち使った方がいいですね。