2

I am trying to make my Django redis celery project on with docker-compose, but there is no way it is starting. Here is the docker-compose file

version: "3.9"

services:
  db: 
    container_name: my_table_postgres
    image: postgres
    ports:
      - 5432/tcp
    volumes:
      - my_table_postgres_db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=my_table_postgres
      - POSTGRES_USER=dev
      - POSTGRES_PASSWORD=Ieyh5&RIR48!&8fc

  redis: 
    container_name: redis
    image: redis

  my_table:
    container_name: my_table
    build: .
    command: python manage.py runserver 0.0.0.0:5000
    volumes:
      - .:/api
    ports:
      - "5000:5000"
    depends_on:
      - db
      - redis

  celery:
    restart: always
    build:
      context: .
    command: ['celery', '-A', 'mytable', '-l', 'INFO']
    volumes:
      - .:/api
    container_name: celery
    depends_on:
      - db
      - redis
      - my_table

volumes:
  my_table_postgres_db:
  redis_data:

And that is the Dockerfile:

FROM python:3.11

# Managing user
RUN mkdir /mytable
RUN useradd -ms /bin/bash devuser
USER devuser
COPY . /mytable
WORKDIR /mytable

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

COPY --chown=devuser:devuser requirements.txt requirements.txt
RUN pip install --user --default-timeout=1000 --upgrade pip
RUN pip install --user --default-timeout=1000 -r requirements.txt

EXPOSE 5000

#ENV PATH="/home/devuser/.local/bin"

COPY --chown=devuser:devuser . .

# Run manage.py runserver when the container launches
CMD ["python3", "manage.py", "runserver"]

And here is the full error that I get when I try to run docker-compose up --build

Recreating eda7aad3f246_celery ... error

ERROR: for eda7aad3f246_celery  Cannot start service celery: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "celery": executable file not found in $PATH: unknown

ERROR: for celery  Cannot start service celery: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "celery": executable file not found in $PATH: unknown        
ERROR: Encountered errors while bringing up the project.

Does someone know how to fix it? I read several similar questions on this forum, but the only thing that I changed was passing from the one line command, to the parenthesis command in docker compose, and that did not work.

Any suggestion? Thank you

2
  • The problem comes from your celery service ("Cannot start service celery") but you did not provided its Dockerfile in your question. Please add the relevant details. Commented Jan 11, 2023 at 14:26
  • 2
    I added it, but it did not work anyway. i fixed it changing the command from ['celery', '-A', 'mytable', '-l', 'INFO'] to adding python -m at the beginning Commented Jan 11, 2023 at 16:23

2 Answers 2

3

i faced the same issue and resolved it like this:

  1. you need to added celery in the requirements.txt file
  2. in your root directory $docker compose up -d --build
  3. in your root directory $docker compose up
Sign up to request clarification or add additional context in comments.

Comments

0

The error exec: "celery": executable file not found in $PATH occurs because the celery executable is not installed globally or is not in the $PATH of the container. When you install Python packages using pip install --user, they are installed in the user's local directory (e.g., ~/.local/bin), which is not included in the system $PATH by default.

To fix this issue, you need to ensure that the celery executable is available in the $PATH. Try to add this line to your dockerfile:

ENV PATH="/home/devuser/.local/bin:${PATH}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.