gpt4 book ai didi

Docker-compose 错误—— panic : runtime error: index out of range [1] with length 1

转载 作者:行者123 更新时间:2023-12-04 13:07:04 35 4
gpt4 key购买 nike

我一直在尝试让 Docker 与 Postgres 和 Flask 一起工作,但我遇到了 Postgres 密码和 docker 无法找到我的 entry.sh 文件的问题。这似乎是 docker 未正确更新的问题,但现在更新后,当我运行 docker-compose up 时出现“go”错误,我不知道它们是什么意思。
这是错误日志:

panic: runtime error: index out of range [1] with length 1

goroutine 37 [running]:
github.com/docker/compose-cli/pkg/compose.(*convergence).ensureService(0xc00027ff20, 0x2120ba8, 0xc000454450, 0xc000240f00, 0xc0001ce7c8, 0x3, 0x0, 0x0, 0x0, 0xc000240a00, ...)
github.com/docker/compose-cli/pkg/compose/convergence.go:222 +0x11f1
github.com/docker/compose-cli/pkg/compose.(*convergence).apply.func1(0x2120ba8, 0xc000454450, 0xc0001ce7c8, 0x3, 0x0, 0x0)
github.com/docker/compose-cli/pkg/compose/convergence.go:99 +0x21f
github.com/docker/compose-cli/pkg/compose.run.func1(0x0, 0x0)
github.com/docker/compose-cli/pkg/compose/dependencies.go:102 +0xa3
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc000590540, 0xc000626180)
golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x59
created by golang.org/x/sync/errgroup.(*Group).Go
golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x66
这是我的 docker-compose.yml:
services:
api:
container_name: api
build:
context: .
dockerfile: api/Dockerfile.api
image: mutcompute-api
ports:
- "5000:5000"
volumes:
- ./api:/app/
env_file:
- ./api/.env
command: gunicorn -b 0.0.0.0:5000 api:app && flask db upgrade
# entrypoint: ["./api/entry.sh"]
depends_on:
- db
client:
container_name: client
build:
context: .
dockerfile: client/Dockerfile.client
image: mutcompute-client
ports:
- "3000:3000"
volumes:
- ./client:/app/
email:
container_name: email
build:
context: .
dockerfile: api/Dockerfile.api
image: mutcompute-api
ports:
- "8025:8025"
command: python -m smtpd -n -c DebuggingServer 0.0.0.0:8025
db:
image: postgres:13-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: mutcompute
POSTGRES_PASSWORD: mutcompute
POSTGRES_DB: mutcompute_dev
networks:
- default
ports:
- 5405:5432
restart: always
volumes:
- ./postgres-data:/var/lib/postgresql/data
我的 Dockerfile:
FROM python:slim

LABEL maintainer="Brad Alexander"

RUN useradd mutcompute

WORKDIR /app

COPY . /app/
COPY entry.sh /app/

ENV FLASK_APP api.py

RUN chown -R mutcompute:mutcompute /app && \
# chmod +x ./entry.sh && \
pip install -r requirements.txt

USER mutcompute

EXPOSE 5000
和一个粗略的文件树
Project
|-api
|-app/
|-Dockerfile-api
|-entry.sh
|-client
|-src/
|-Dockerfile-client
|-Docker-compose.yml
客户端是 React,在更新之前运行良好。
有时,当我编辑撰写文件时,它开始重新创建 api 容器,然后像这样失败:
⠙ Container api               Recreate                                                                                                                                                       0.2s
⠙ Container bb72362b9e19_api Recreate 0.2s
panic: runtime error: index out of range [1] with length 1
...
希望这是足够的信息。我真的很感激任何帮助!

最佳答案

域名注册地址:
我想我在后台有绑定(bind)端口的容器。
简单修复:

docker-compose up --remove-orphans // not sure if this step is necessary
docker-compose down
docker-compose up
我是如何修复它的:
我切换到以前没有db服务的版本,提示运行 docker-compose --remove -orphans ,这实际上并没有多大作用。在搜索了 GitHub 问题后,看到大部分问题都与副本有关,我决定到底是什么,并在 api 服务中添加了副本部分。虽然这个错误与副本无关,但我得到了一个不同的错误:

WARNING: The "api" service is using the custom container name "api". Docker requires each container to have a unique name. Remove the custom name to scale the service.


对于这个错误,我只是注释掉了每个服务中的所有 container_name 部分,并得到了一个新错误:

Error response from daemon: driver failed programming external connectivity on endpoint <...> Bind for 0.0.0.0:5000 failed: port is already allocated


繁荣!这是真正的问题。为此搜索 SO,发现我只需要运行 docker-compose down当我用 db 服务切换回分支时,一切正常!

关于Docker-compose 错误—— panic : runtime error: index out of range [1] with length 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68900909/

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