Docker で centos 7 をベースに Hadoop(version3.1.3) コンテナ作成したときの問題
Docker で centos 7 をベースに Hadoop(version3.1.3) コンテナ作成してみました。
ただ作成してみたものの、使いづらいと感じている面があります。
理由1
systemctlを使ったサービスの自動起動を行うには、コンテナ起動時に/sbin/initを指定しなければならない
また、その指定のほかに管理者権限モードのオプション(--privileged、または、--cap-add=SYS_ADMIN)が必要になる。
しかしながら、管理者権限モードで実行されたDockerコンテナは、ホストOSのハードウェア資源(デバイスなど)へのアクセスが無制限に許可されるため、セキュリティ面において注意が必要。
自分の場合は、docker-compose を使っているため、以下のように指定する必要があります。
privileged: true command: /sbin/init
Hadoop においては、hdfs(Namenode, Datanode) を起動するための ssh サービスを起動するため、この設定が必須でした。
個人のローカル環境においてのみであれば、セキュリティ面に関しては気にする必要はないかもしれません。
理由2
command: /sbin/init を指定するため、本来使いたいスタートアップ用のスクリプトが起動できなかった
コンテナの起動時に実行させたいスクリプト(start.sh) がある場合、本来であれば command や endpoint に指定することで起動させることができますが、command: /sbin/init が必須であるため、start.sh を指定してあげることができませんでした。
以下のように指定したり、start.sh 内に /sbin/init を記述するなど試行錯誤しましたが結果動作させることが出来ず。
command: /sbin/init && /opt/hadoop/current/start.sh command: bash -c "/sbin/init && /opt/hadoop/current/start.sh" command: bash -c "exec /sbin/init && /opt/hadoop/current/start.sh"
今のところ、一旦コンテナを起動させた後に、start.sh を実行してあげる必要があります。
docker-compose を実行した後に start.sh を実行させるラッパーシェルを用意してあげれば手間にはならないかもしれません。
とは言え、これらの問題はベースとなるDocker Image(今回は centos7 など systemctl を採用)に依存するものであり、他のDocker Image を使用することで問題が回避できる可能性があるので、別の Docker Imageでも試行したいと考えています。
参考
https://qiita.com/hiraike32/items/140d48165b957fbbbfaf
https://stackoverflow.com/questions/48129029/hdfs-namenode-user-hdfs-datanode-user-hdfs-secondarynamenode-user-not-defined
http://hadoop2help.blogspot.com/2018/06/310-301-start-dfssh-stop-dfssh-wont-run.html
https://phoenixnap.com/kb/how-to-enable-ssh-centos-7
https://www.opensourcetech.tokyo/entry/20190222/1550822082
https://hub.docker.com/_/centos?tab=description
https://qiita.com/naokism/items/4ac0d15476b516fd1fc3
https://qiita.com/mikene_koko/items/4c71c969f55e3fe24190
https://naoty.dev/posts/103.html
https://qiita.com/gakuseikai/items/e1ff2f2920951bbefd02
https://cwiki.apache.org/confluence/display/HADOOP2/ConnectionRefused
https://teratail.com/questions/26092
https://qiita.com/haisaihiroki/items/87fe137f00b5c625f607
http://linuxcommand2007.seesaa.net/article/401670498.html
https://stackoverflow.com/questions/49967645/failed-to-start-namenode-directory-is-in-an-inconsistent-state-storage-directo