gpt4 book ai didi

docker - 为什么docker compose在启动后立即退出?

转载 作者:行者123 更新时间:2023-12-02 19:08:42 29 4
gpt4 key购买 nike

我正在尝试将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表示它既不是“官方的”,也不是“受支持的”;

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 pa-toolsmiths@pivotal.io 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-composedocker 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。附加了 bashtty shell 程序立即退出,此时容器退出。

运行此图像

(再次;请谨慎运行此图像)

通过传递 stdintty(以 -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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com