gpt4 book ai didi

azure - 在 CircleCI 中找不到 postgres_1 的容器

转载 作者:行者123 更新时间:2023-12-02 19:20:27 25 4
gpt4 key购买 nike

我有一个circleCI脚本,它在Azure容器中运行docker-compose exec postgres pg_isready命令设置,但我们收到了代码构建错误,如下所示。相同的脚本早些时候运行良好,但从过去几天我们得到了这个。

running docker-compose up
Creating network "docker_default" with the default driver
Pulling postgres (postgres:9.6)...
9.6: Pulling from library/postgres


Status: Downloaded newer image for postgres:9.6

Creating docker_myproject_1 ...

Creating docker_postgres_1 ...

waiting for postgres to startAttaching to docker_myproject_1
ERROR: No container found for postgres_1
myproject_1 | 2020-02-18T14:40:42.317723661Z starting...
.myproject_1 | 2020-02-18T14:40:43.718394751Z {"name":"myproject","hostname":"xxxxxx","pid":1,"level":30,"msg":"myproject app version v2.8 listening on port 3030 (Node.js version 8.17.0, ci environment)","time":"2020-02-18T14:40:43.717Z","v":0}
myproject_1 | 2020-02-18T14:40:43.718573206Z myproject app version v2.8 listening on port 3030 (Node.js version 8.17.0, ci environment)
myproject_1 | 2020-02-18T14:40:43.793220191Z Failed to prune sessions: getaddrinfo ENOTFOUND postgres postgres:5432
ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.ERROR: No container found for postgres_1
.Too many attempts

CircleCI 配置文件 --- config.yml

version: 2
jobs:
build:
working_directory: /home/circleci/app

docker:
- image: circleci/node:8-browsers
- image: circleci/postgres:9.6-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_DB: myproject_ci

steps:
# Prepare build environment
- setup_remote_docker:
reusable: true
- checkout
- restore_cache:
key: dependency-cache-v2-{{ checksum "package.json" }}

# Install dependencies + cache them
- run: npm install
- save_cache:
key: dependency-cache-v2-{{ checksum "package.json" }}
paths:
- node_modules

# Build
- run: CONFIG_ENV=ci npm run build

# Start for testing
- run:
command: ./scripts/run-ci.sh
background: true
- run: ./scripts/run-ci-wait.sh

# Run tests
- run: CONFIG_ENV=ci npm test

# Run tests for docker image
- run: ./test/docker/run-docker-tests.sh

- deploy:
name: Deploy master to dev
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
./scripts/deploy-dev.sh
fi

run-docker-tests.sh 失败的内容

#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

function cleanup() {
docker-compose down || true
}
trap cleanup SIGINT SIGTERM EXIT

echo 'running docker-compose down'
docker-compose down
echo 'running docker-compose up'
docker-compose up -d --force-recreate
docker-compose logs --follow --timestamps --no-color myproject &

printf 'waiting for postgres to start'
attempt=0
until docker-compose exec postgres pg_isready; do
printf '.'
sleep 2
attempt=$(( $attempt + 1 ))
if [ $attempt -gt 15 ]; then
echo Too many attempts
exit 1
fi
done
echo 'postgres is started'

printf 'waiting for server to start'
attempt=0
until docker-compose run -T myproject curl --output /dev/null --silent --head --fail http://myproject:3030; do
printf '.'
sleep 2
attempt=$(( $attempt + 1 ))
if [ $attempt -gt 15 ]; then
echo Too many attempts
exit 1
fi
done
echo 'server is started'


过去一周使用相同的脚本成功构建。

Status: Downloaded newer image for postgres:9.6

Creating docker_postgres_1 ...

Creating docker_myproject_1 ...

waiting for postgres to startAttaching to docker_myproject_1
myproject_1 | 2020-02-14T14:57:56.436816113Z starting...
^@^@/var/run/postgresql:5432 - no response
myproject_1 | 2020-02-14T14:57:58.305638546Z {"name":"myproject","hostname":"xxxxxx","pid":1,"level":30,"msg":"myproject app version v2 listening on port 3030 (Node.js version 8.17.0, ci environment)","time":"2020-02-14T14:57:58.305Z","v":0}
myproject_1 | 2020-02-14T14:57:58.306243774Z myproject app version v2 listening on port 3030 (Node.js version 8.17.0, ci environment)
.myproject_1 | 2020-02-14T14:57:58.413266214Z Failed to prune sessions: connect ECONNREFUSED x.x.x.x:5432
/var/run/postgresql:5432 - no response
./var/run/postgresql:5432 - accepting connections
postgres is started
waiting for server to startserver is started

撰写文件

version: "3"

services:
myproject:
image: myproject:latest
environment:
- CONFIG_ENV=ci
- CONFIG_PASSWORD
- POSTGRES_HOST=postgres
postgres:
image: postgres:9.6
environment:
- POSTGRES_DB=myproject_ci

这里的任何帮助都会很棒。

最佳答案

在您的docker-compose.yml文件中,请检查environment参数下是否提供了。如果未提供,请提供如下内容:- POSTGRES_HOST_AUTH_METHOD=trust

这个解决方案对我们有用,导致此构建问题的原因应该是 Postgres 的 Docker 官方镜像最近已更新,这导致了以前工作的 PG 容器出现许多新问题现在在初始化时抛出错误。

更多信息请点击这里: https://github.com/docker-library/official-images/commit/044fa382fb4ce789c44636bf5ca1b4aca253fa0f#diff-24ff720298244763c283810044b398c8

关于azure - 在 CircleCI 中找不到 postgres_1 的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60283904/

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