Open8
何もわからない状態からdocker-compose.ymlを試す

自前で作ったDockerコンテナがある。
いまはひとつのコンテナの中に様々なエコシステムが乗っている。
最終的に各エコシステムごとにコンテナを分けたい。

見まねでdocker-compose.ymlを作成
version: "3"
services:
my-container:
build:
context: .
dockerfile: ./Dockerfile
tty: true
下を実行するとひとつのコンテナが作られ、コンテナの中に入ることもできる。
$ docker-compose up --build -d
Building my-container
[+] Building 0.2s (34/34) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
...
$ docker-compose exec my-container /bin/bash
root@76a7e3f121c1:~/work#

同じ内容のコンテナを2つ作ってssh接続を試す。
version: "3"
services:
my-container1:
build:
context: .
dockerfile: ./Dockerfile
tty: true
hostname: my-container1
my-container2:
build:
context: .
dockerfile: ./Dockerfile
tty: true
hostname: my-container2
$ docker-compose exec my-container1 /bin/bash
root@my-container1:~/work# ssh my-container2
root@my-container2:~#

my-container2のpostgreにつなげる
root@my-container1:~/work# grep jdbc $HIVE_HOME/conf/hive-site.xml
<value>jdbc:postgresql://my-container2:5432/hive</value>
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
root@my-container2:~/work# grep listen_address /etc/postgresql/9.5/main/postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
root@my-container2:~/work# grep trust /etc/postgresql/9.5/main/pg_hba.conf | grep host
host all all 172.24.0.2/32 trust

postgreのDBサーバを分離することができた。
docker-compose.yml
version: "3"
services:
my-container1:
build:
context: .
dockerfile: ./Dockerfile
tty: true
hostname: my-container1
my-container2:
build:
context: .
dockerfile: ./Dockerfile
tty: true
hostname: my-container2
postgres95:
image: postgres:9.5
environment:
- POSTGRES_USER=hive
- POSTGRES_PASSWORD=hive
- POSTGRES_DB=hive
ports:
- 5432:5432
root@my-container1:~/work# grep jdbc $HIVE_HOME/conf/hive-site.xml
<value>jdbc:postgresql://postgres95:5432/hive</value>
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.

各コンテナで共通で使用する環境変数は .env
に書くことができる。

docker-compose build するともとのIMAGEに中間レイヤーが追加されていた
$ docker history ubuntu_impala3.4.1
IMAGE CREATED CREATED BY SIZE COMMENT
fe9db9712e5a 33 seconds ago CMD ["/bin/sh" "-c" "/bin/bash"] 0B buildkit.dockerfile.v0
<missing> 33 seconds ago COPY ./tez-site.xml /opt/impala/conf # build… 333B buildkit.dockerfile.v0
<missing> 33 seconds ago COPY ./hive-site.xml /opt/impala/conf # buil… 2.03kB buildkit.dockerfile.v0
<missing> 33 seconds ago COPY ./yarn-site.xml /opt/impala/conf # buil… 1.07kB buildkit.dockerfile.v0
<missing> 33 seconds ago COPY ./mapred-site.xml /opt/impala/conf # bu… 1.06kB buildkit.dockerfile.v0
<missing> 33 seconds ago COPY ./core-site.xml /opt/impala/conf # buil… 890B buildkit.dockerfile.v0
<missing> 33 seconds ago COPY ./hdfs-site.xml /opt/impala/conf # buil… 977B buildkit.dockerfile.v0
<missing> 33 seconds ago WORKDIR /root/work 0B buildkit.dockerfile.v0
<missing> 33 seconds ago RUN /bin/sh -c mkdir -p /opt/impala/conf # b… 0B buildkit.dockerfile.v0
<missing> 33 seconds ago RUN /bin/sh -c mkdir -p /root/work # buildkit 0B buildkit.dockerfile.v0
<missing> 7 minutes ago bash 18.2GB
<missing> 11 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 11 months ago /bin/sh -c mkdir -p /run/systemd && echo 'do… 7B
<missing> 11 months ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0B
<missing> 11 months ago /bin/sh -c set -xe && echo '#!/bin/sh' > /… 745B
<missing> 11 months ago /bin/sh -c #(nop) ADD file:11b425d4c08e81a3e… 135MB

buildとimage両方設定していたからだった
catalogd:$
build:$
context: .$
dockerfile: ./Dockerfile_impala$
args:$
- IMPALA_HOME=$IMPALA_HOME$
image: ubuntu_impala3.4.1$