简体   繁体   English

在 docker 容器中运行迁移时出错

[英]Error running migrations in a docker container

I am getting this error when trying to run migrations in my container.尝试在容器中运行迁移时出现此错误。 I cannot seem to figure out why.我似乎无法弄清楚为什么。

Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"alembic\": executable file not found in $PATH": unknown

Dockerfile: Dockerfile:

FROM python:3.8.2
WORKDIR /workspace/
COPY . .
RUN pip install pipenv
RUN pipenv install --deploy --ignore-pipfile
#EXPOSE 8000
#CMD ["pipenv", "run", "python", "/workspace/bin/web.py"]

Docker-Compose: Docker-Compose:

version: '3'
services:
  db:
    image: postgres:12
    ports:
      - "5432:5432"
    env_file:
      - .env.database.local
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    environment:
      - PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
      - PGADMIN_DEFAULT_PASSWORD=admin
    ports:
      - "5050:80"
    depends_on:
      - db
  redis:
    image: "redis:alpine"
  web:
    build: .
    environment:
      - PYTHONPATH=/workspace
    env_file:
      - .env.local
    ports:
      - "8000:8000"
    volumes:
      - .:/workspace
    depends_on:
      - db
      - redis
    command: "alembic upgrade head && pipenv run python /workspace/bin/web.py"

The command I run when I encounter this problem:遇到此问题时运行的命令:

docker-compose run web alembic revision - autogenerate -m "First migration"

项目目录。

I defined in my Dockerfile that all my program will be running in the workspace directory.我在 Dockerfile 中定义了我的所有程序都将在工作区目录中运行。 So it should point to it.所以它应该指向它。

Yes the issue was that I did not add it to my $PATH.是的,问题是我没有将它添加到我的 $PATH 中。

This is what I added inside my docker-compose:这是我在 docker-compose 中添加的内容:

      - PATH=/directory/bin:$PATH

docker-compose run web pipenv run alembic revision - autogenerate -m "First migration"

or change in Dockerfile或更改 Dockerfile

RUN pipenv install --deploy --ignore-pipfile --system

and run并运行

docker-compose run web alembic revision - autogenerate -m "First migration"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM