1

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"

Project Directory.

I defined in my Dockerfile that all my program will be running in the workspace directory. So it should point to it.

Kendrick Lamar
  • 781
  • 2
  • 8
  • 18
  • 1
    Looks like `alembic` isn't in your container `PATH`. Does your docker image have `alembic` included? You may have to manually install it in the `Dockerfile` if not. – puppydog May 05 '20 at 21:26
  • It should already be installed because of pipenv. Which is what I am confused about. – Kendrick Lamar May 05 '20 at 21:51
  • 1
    Hm. Where is `pipenv` installing it to? `alembic` could be installed but your container doesn't know where to find it because the shell `PATH` variable doesn't include the path to the `alembic` executable. – puppydog May 05 '20 at 21:56
  • alembic is a binary thats sitting inside the venv pipenv creates. @jonsbox, answer is correct but missing the context. – The Fool Jun 13 '22 at 18:05

2 Answers2

0

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
Kendrick Lamar
  • 781
  • 2
  • 8
  • 18
0

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"

jonsbox
  • 472
  • 1
  • 6
  • 13