Render's dockerCommand vs docker-compose

Hi, I have the following dockerfile (backend.dockerfile):

FROM python:3.10.7

WORKDIR /app

RUN apt-get update
RUN apt-get install -y coinor-cbc

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
    cd /usr/local/bin && \
    ln -s /opt/poetry/bin/poetry && \
    poetry config virtualenvs.create false


# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./pyproject.toml ./poetry.lock* /app/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=true
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then POETRY_VIRTUALENVS_CREATE=false poetry install --no-root ; else POETRY_VIRTUALENVS_CREATE=false poetry install --no-root --no-dev ; fi"

COPY . /app

Here’s a snippet of my docker-compose.yml file:

  backend:
    build:
      context: backend
      dockerfile: backend.dockerfile
    command: bash -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8888 --reload"
    ports:
      - '8888:8888'
    tty: true
    volumes:
      - ./backend:/app/:cached
      - ./.docker/.ipython:/root/.ipython:cached
    env_file:
      - ./backend/.env

Here’s a snipper of our render.yaml

services:
  - type: web
    name: BelfryAPI
    env: docker
    region: ohio
    plan: pro
    previewPlan: starter
    dockerfilePath: ./backend/backend.dockerfile
    dockerContext: ./backend
    dockerCommand: 

I would like the dockerCommand to run the same command as the command in docker-compose.yml, but I seem to be unable to do so.

The following command, command: bash -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8888 --reload" works both within the dockerfile (as CMD bash -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8888 --reload") and within docker-compose.yml (command: bash -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8888 --reload")

Would you be able to point us to a direction whether we can both run alembic and uvicorn using dockerCommand within render.yml. Thank you in advance for your help and patience!

Hi there,

Thanks for reaching out.

I’ve seen some Docker Command queries in the past, which seem like they may be related to how the syntax is parsed and the complexity of the command being passed to it. I’ll make a note to raise this with the engineers to see if they have any input.

However, a workaround I’ve seen to be successful is to wrap your command in a script, making your Docker Command a lot more simple, e.g.

dockerCommand: ./render-start-cmd.sh

and render-start-cmd.sh would contain something like:

#!/bin/bashalembic upgrade headuvicorn main:app --host 0.0.0.0 --port $PORT --reload

Hope that helps

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.