简体   繁体   中英

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:

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:

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. So it should point to it.

Yes the issue was that I did not add it to my $PATH.

This is what I added inside my docker-compose:

      - PATH=/directory/bin:$PATH

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

or change in Dockerfile

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

and run

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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