我正在尝试将Docker映像“ postgis / postgis:latest”用作GitLab CI中的服务,但该服务无法启动。这是CI日志的开始,最后一行是最重要的:
Running with gitlab-runner 12.9.0 (4c96e5ad)
on xxxxxxx xxxxxxxx
Preparing the "docker" executor
Using Docker executor with image node:lts-stretch ...
Starting service redis:latest ...
Pulling docker image redis:latest ...
Using docker image sha256:4cdbec704e477aab9d249262e60b9a8a25cbef48f0ff23ac5eae879a98a7ebd0 for redis:latest ...
Starting service postgis/postgis:latest ...
Pulling docker image postgis/postgis:latest ...
Using docker image sha256:a412dcb70af7acfbe875faea4467a1594e7cba3dfca19e5e1c6bcf35286380df for postgis/postgis:latest ...
Waiting for services to be up and running...
*** WARNING: Service runner-xxxxxxxx-project-1-concurrent-0-postgis__postgis-1 probably didn't start properly.
Health check error:
service "runner-xxxxxxxx-project-1-concurrent-0-postgis__postgis-1-wait-for-service" timeout
Health check container logs:
Service container logs:
2020-04-06T11:58:09.487216183Z The files belonging to this database system will be owned by user "postgres".
2020-04-06T11:58:09.487254326Z This user must also own the server process.
2020-04-06T11:58:09.487260023Z
2020-04-06T11:58:09.488674041Z The database cluster will be initialized with locale "en_US.utf8".
2020-04-06T11:58:09.488696993Z The default database encoding has accordingly been set to "UTF8".
2020-04-06T11:58:09.488704024Z The default text search configuration will be set to "english".
2020-04-06T11:58:09.488710330Z
2020-04-06T11:58:09.488716134Z Data page checksums are disabled.
2020-04-06T11:58:09.488721778Z
2020-04-06T11:58:09.490435786Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
2020-04-06T11:58:09.490649106Z creating subdirectories ... ok
2020-04-06T11:58:09.490656485Z selecting dynamic shared memory implementation ... posix
2020-04-06T11:58:09.525841255Z selecting default max_connections ... 100
2020-04-06T11:58:09.562735034Z selecting default shared_buffers ... 128MB
2020-04-06T11:58:09.614695491Z selecting default time zone ... Etc/UTC
2020-04-06T11:58:09.616784837Z creating configuration files ... ok
2020-04-06T11:58:09.917724902Z running bootstrap script ... ok
2020-04-06T11:58:10.767115421Z performing post-bootstrap initialization ... ok
2020-04-06T11:58:10.924542026Z syncing data to disk ... ok
2020-04-06T11:58:10.924613120Z
2020-04-06T11:58:10.924659485Z initdb: warning: enabling "trust" authentication for local connections
2020-04-06T11:58:10.924720453Z You can change this by editing pg_hba.conf or using the option -A, or
2020-04-06T11:58:10.924753751Z --auth-local and --auth-host, the next time you run initdb.
2020-04-06T11:58:10.925150488Z
2020-04-06T11:58:10.925175359Z Success. You can now start the database server using:
2020-04-06T11:58:10.925182577Z
2020-04-06T11:58:10.925188661Z pg_ctl -D /var/lib/postgresql/data -l logfile start
2020-04-06T11:58:10.925195041Z
2020-04-06T11:58:10.974712774Z waiting for server to start....2020-04-06 11:58:10.974 UTC [47] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-04-06T11:58:10.976267115Z 2020-04-06 11:58:10.976 UTC [47] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-04-06T11:58:11.003287980Z 2020-04-06 11:58:11.002 UTC [48] LOG: database system was shut down at 2020-04-06 11:58:10 UTC
2020-04-06T11:58:11.011056242Z 2020-04-06 11:58:11.010 UTC [47] LOG: database system is ready to accept connections
2020-04-06T11:58:11.051536096Z done
2020-04-06T11:58:11.051578164Z server started
2020-04-06T11:58:11.051855017Z
2020-04-06T11:58:11.052088262Z /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
2020-04-06T11:58:11.218053189Z psql: error: could not connect to server: could not translate host name "postgres" to address: Name or service not known
无法将主机名“ postgres”转换为地址:名称或服务未知
在我看来,主机“ postgres”是错误的。但是GitLab的文档表明主机名将是别名:https://docs.gitlab.com/ce/ci/docker/using_docker_images.html#accessing-the-services
我的.gitlab-ci-yml摘录:
image: node:lts-stretch
services:
- name: redis:latest
- name: postgis/postgis:latest
alias: postgres
variables:
NODE_ENV: production
REDIS_HOST: redis
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGHOST: postgres
PGUSER: postgres
PGPASSWORD: postgres
我还尝试删除别名,并根据文档名使用“ postgis-postgis”或“ postgis__postgis”作为主机名,但是每次都出现相同的错误。我也尝试使用docker映像“ mdillon / postgis”,因为我经常看到它,但是也有相同的错误。
我尝试插入您的.gitlab-ci.yml摘录,但出现错误:
This GitLab CI configuration is invalid: jobs config should contain at least one visible job
下一次请提供一个最小的可复制示例。 ;)
我能够重现并解决该问题。解决方法是删除PGHOST
设置。 (您将其值设置为postgres
。您的主容器可以使用别名postgres
进入postgis容器,但postgis容器本身不需要主机名即可访问PostgreSQL服务,因为该服务正在监听本地套接字。)
PGHOST
在脚本psql
(以services
结尾–见https://github.com/postgis/docker-postgis/blob/master/initdb-postgis.sh)中,在“ postgis”容器中由/docker-entrypoint-initdb.d/10_postgis.sh
使用(由https://github.com/postgis/docker-postgis/blob/master/Dockerfile.template#L16指令启动)。
以下.gitlab-ci.yml
有效:
image: node:lts-stretch variables: POSTGRES_DB: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres PGUSER: postgres PGPASSWORD: postgres services: - name: postgis/postgis:latest alias: postgres job1: script: ping -c 3 postgres
这是作业日志:
Running with gitlab-runner 12.9.0 (4c96e5ad) on docker-auto-scale 0277ea0f Preparing the "docker+machine" executor Using Docker executor with image node:lts-stretch ... Starting service postgis/postgis:latest ... Pulling docker image postgis/postgis:latest ... Using docker image sha256:a412dcb70af7acfbe875faea4467a1594e7cba3dfca19e5e1c6bcf35286380df for postgis/postgis:latest ... Waiting for services to be up and running... Pulling docker image node:lts-stretch ... Using docker image sha256:88c089733a3b980b3517e8e2e8afa46b338f69d7562550cb3c2e9fd852a2fbac for node:lts-stretch ... Preparing environment 00:05 Running on runner-0277ea0f-project-17971942-concurrent-0 via runner-0277ea0f-srm-1586221223-45d7ab06... Getting source from Git repository 00:01 $ eval "$CI_PRE_CLONE_SCRIPT" Fetching changes with git depth set to 50... Initialized empty Git repository in /builds/atsaloli/service-postgis/.git/ Created fresh repository. From https://gitlab.com/atsaloli/service-postgis * [new ref] refs/pipelines/133464596 -> refs/pipelines/133464596 * [new branch] master -> origin/master Checking out d20469e6 as master... Skipping Git submodules setup Restoring cache 00:02 Downloading artifacts 00:01 Running before_script and script 00:04 $ ping -c 3 postgres PING postgres (172.17.0.3) 56(84) bytes of data. 64 bytes from postgis-postgis (172.17.0.3): icmp_seq=1 ttl=64 time=0.077 ms 64 bytes from postgis-postgis (172.17.0.3): icmp_seq=2 ttl=64 time=0.064 ms 64 bytes from postgis-postgis (172.17.0.3): icmp_seq=3 ttl=64 time=0.060 ms --- postgres ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2062ms rtt min/avg/max/mdev = 0.060/0.067/0.077/0.007 ms Running after_script 00:01 Saving cache 00:02 Uploading artifacts for successful job 00:01 Job succeeded
您可以在上面的ping命令中看到,从image节点创建的容器:lts-stretch可以使用postgres别名访问postgis容器。
可以解除对您的封锁吗?