I would like to build one image and run multiple containers against same image with containers running on different ports
I have following docker file
FROM python:3.9
ARG port
RUN mkdir /code
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./mock_s /code/mock_s
ENTRYPOINT ["uvicorn", "mock_s.main:app", "--port", "$port"]
and docker compose file
version: "3"
services:
mock-server-1:
container_name: mock-s1
build:
context: .
args:
port: ${MOCK_SERVER_HOST_PORT_1}
ports:
- "${MOCK_SERVER_HOST_PORT_1}:8003"
For brevity, I am not showing code for mock-server-2, 3 and so on. but it only differs by reference to port variable ${MOCK_SERVER_HOST_PORT_1}, ${MOCK_SERVER_HOST_PORT_2} and so on
.env file is
MOCK_SERVER_HOST_PORT_1=8003
MOCK_SERVER_HOST_PORT_2=8004
but on docker compose up
I get following error
Error: Invalid value for '--port': '${port}' is not a valid integer.
This indicates ${port}
is not expanded when container is not run.
Any thoughts what might be wrong here?