Ehs*_*nia 5 python django postgresql docker gitlab-ci
我在这个项目中使用了 docker 和 django,并且 gitlab ci/cd pipleline 和测试甚至无法启动和退出,出现以下错误:
测试一直在运行,直到我在 django 应用程序中添加一些测试,然后它失败了。
django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known
Run Code Online (Sandbox Code Playgroud)
这是我的 Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
Run Code Online (Sandbox Code Playgroud)
我的 docker-compose.yml:
version: "3.9"
services:
db:
image: postgres
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
Run Code Online (Sandbox Code Playgroud)
和我的 gitlab-ci.yml:
image: python:latest
services:
- mysql:latest
- postgres:latest
variables:
POSTGRES_DB: postgres
cache:
paths:
- ~/.cache/pip/
test:
variables:
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
script:
- pip install -r requirements.txt
- python manage.py test
build:
image: docker:19.03.12
stage: build
services:
- docker:19.03.12-dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
Run Code Online (Sandbox Code Playgroud)
小智 0
为 docker-compose 文件中的容器创建网络,并在您的app和db.
像这样的东西
db:
networks:
- network_name
# your other db setup follows
web:
networks:
- network_name
# your other web setup follows
networks:
network_name:
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
707 次 |
| 最近记录: |