首页 > 解决方案 > docker 容器不会在 Amazon Codebuild 上启动 postgres 服务器

问题描述

我正在使用自定义 docker 容器来构建代码,该容器与 Amazon codebuild 集成。AWS codebuild 启动一个 Docker 容器并在我们提供的容器上构建代码。我写的容器的 Dockerfile 是这样的 -> Dockerfile

Docker 容器应该安装了 Java-8、Gradle-4.7 和 Postgres-10。

我在本地机器上运行 Docker 容器,可以看到 Postgres 服务正在运行。但是,在 AWS codebuild 上,docker 容器不会启动 Postgres 服务器。我尝试使用 buildspec.yml 文件中的命令了解 Postgres 的状态,结果发现它已关闭。

以下是我可以在 cloudwatch 日志中看到的错误 -

May 18, 2018 9:26:33 AM org.postgresql.Driver connect
SEVERE: Connection error: 
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

有人对此有任何想法吗?Dockerfile 是否正确?

标签: postgresqlamazon-web-servicesdockeraws-codepipelineaws-codebuild

解决方案


问题实际上可能是入口点(在您提到的 Dockerfile 中)。

CodeBuild 将覆盖每次运行时的入口点,这与您在本地 docker run 中看到的不同(您也可以使用 codebuild 本地代理测试此行为)

"ENTRYPOINT ["/etc/init.d/postgresql", "start"]"

您可以发布您的 buildspec.yml 文件吗?对此的简单解决方法是将入口点命令作为 buildspec.yml 的一部分运行


推荐阅读