我正在尝试配置docker-compose在 Ubuntu 16.04 中使用 GreenPlum 数据库。这是我的 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 hubtaldata/gpdb-base
启动它时,就可以了。
docker compose 有什么问题?
最佳答案
首先,小心运行此镜像:该镜像看起来维护得很差,并且 the information on Docker Hub表明它既不是“官方的”,也不是以任何方式“支持的”;
2017-01-09: Toolsmiths reviewed this image; it is not one we create. We make no promises about whether this is up to date or if it works. Feel free to email [email protected] if you are the owner and are interested in collaborating with us on this image.
当使用来自 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
外壳已启动。没有附加 tty
的 bash
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:
关于docker - 为什么docker compose启动后就退出了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44324940/