我正在尝试将docker-compose配置为在Ubuntu 16.04中使用GreenPlum
db。这是我的docker-compose.yml:
version: '2'
services:
greenplum:
image: "pivotaldata/gpdb-base"
ports:
- "5432:5432"
volumes:
- gp_data:/tmp/gp
volumes:
gp_data:
问题是,当我使用
sudo docker-compose up
运行它时,GrrenPlum db在启动后立即被关闭。它看起来像这样:greenplum_1 | 20170602:09:01:01:000050 gpstart:e1ae49da386c:gpadmin-[INFO]:-Starting Master instance 72ba20be3774 directory /gpdata/master/gpseg-1
greenplum_1 | 20170602:09:01:02:000050 gpstart:e1ae49da386c:gpadmin-[INFO]:-Command pg_ctl reports Master 72ba20be3774 instance active
greenplum_1 | 20170602:09:01:02:000050 gpstart:e1ae49da386c:gpadmin-[INFO]:-No standby master configured. skipping...
greenplum_1 | 20170602:09:01:02:000050 gpstart:e1ae49da386c:gpadmin-[INFO]:-Database successfully started
greenplum_1 | ALTER ROLE
dockergreenplumn_greenplum_1 exited with code 0 <<----- Here
实际上,当我只用
sudo docker run pivotaldata/gpdb-base
开头时,就可以了。docker compose有什么问题?
最佳答案
首先,谨慎运行此图像:该图像看起来维护不当,the information on Docker Hub表示它既不是“官方的”,也不是“受支持的”;
当使用来自Docker Hub的镜像时,建议使用官方镜像,或者当不可用时,建议使用自动构建(在这种情况下,可以验证镜像的源代码以查看用于构建镜像的内容)。
我认为该图像是从this GitHub repository构建的,这意味着它已经一年多没有更新了,并且使用了过时的(CentOS 6.7)基本图像has a huge amount of critical vulnerabilities
回到您的问题;
我尝试使用docker-compose
和docker run
来启动图像,并且两者都对我产生了相同的效果。
查看该图像,它被设计为可交互运行,或用作基本图像(并覆盖命令)。
我检查了一下图像,以找出容器的命令是什么;
docker inspect --format='{{json .Config.Cmd}}' pivotaldata/gpdb-base
["/bin/sh","-c","echo \"127.0.0.1 $(cat ~/orig_hostname)\" >> /etc/hosts && service sshd start && su gpadmin -l -c \"/usr/local/bin/run.sh\" && /bin/bash"]
因此,这就是启动容器时执行的操作;
echo "127.0.0.1 $(cat ~/orig_hostname)" >> /etc/hosts \
&& service sshd start \
&& su gpadmin -l -c "/usr/local/bin/run.sh" \
&& /bin/bash"
基于以上内容,容器中没有“前台”进程,因此在
/usr/local/bin/run.sh
完成后,即启动了bash
shell。附加了bash
的tty
shell 程序立即退出,此时容器退出。运行此图像
(再次;请谨慎运行此图像)
通过传递
stdin
和tty
(以-i -t
或-it
为简写形式),以交互方式运行图像;docker run -it pivotaldata/gpdb-base
或者也可以“分离”运行它,只要还传递了
tty
(添加-d
和-t
标志,或-dt
作为速记)即可;这样做可以使容器在后台运行;docker run -dit pivotaldata/gpdb-base
要在
docker-compose
中执行相同的操作,请将tty
添加到您的服务中;tty: true
您的撰写文件将如下所示;
version: '2'
services:
greenplum:
image: "pivotaldata/gpdb-base"
ports:
- "5432:5432"
tty: true
volumes:
- gp_data:/tmp/gp
volumes:
gp_data: