testdriven.io django tdd - got Error: '$' is not a valid port number when running docker run

130 Views Asked by At

Every time I try to run the command

docker run --name django-tdd -e "PORT=8765" -p 8008:8765 registry.heroku.com/lit-sierra-68791/web:latest

I get Error: '$' is not a valid port number

Dockerfile.prod

# pull official base image
FROM python:3.9.5-slim-buster

# set working directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DEBUG 0
ENV SECRET_KEY fgerg345y4y56u5u5757jk5k56kuykykyk
ENV DJANGO_ALLOWED_HOSTS localhost 127.0.0.1 [::1]
ENV PORT 8765

# install system dependencies
RUN apt-get update \
  && apt-get -y install gcc postgresql \
  && apt-get clean

# add and install requirements
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# add app
COPY . .

# add and run as non-root user
RUN adduser --disabled-password myuser
USER myuser

# run gunicorn
CMD gunicorn drf_project.wsgi:application --bind 0.0.0.0:$PORT

I even added the ENV PORT 8765 in the file above, but it didn't worked too.

1

There are 1 best solutions below

0
On BEST ANSWER

ENV variables cannot be referenced in CMD.

You can work around this by creating a script that reads the variable and pass it to CMD.

Create file bin/start.sh

#!/bin/sh
gunicorn drf_project.wsgi:application --bind 0.0.0.0:$PORT

Update Dockerfile

...
CMD ["bin/start.sh"]