Container does not start localhost

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN ln -s /usr/bin/python3 /usr/bin/python
# Встановлюємо wheel для уникнення проблем з установкою
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3-wheel \
    && rm -rf /var/lib/apt/lists/*
RUN python3 -m venv /app/myenv
RUN pip install --upgrade pip setuptools wheel
RUN pip install --use-pep517 -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "./manage.py", "runserver", "0.0.0.0:8000"]

I create Dockerfile, after that i need to push docker container on aws EKS, so when i run

docker run my-container-name

my localhost didn’t run, but when i run like this:

docker run -d -p 8000:8000 my-container-name

all works, and localhost running, so how fix problem, i need to run my container without “-p 8000:8000”
My point to run dockercontainer just with

docker run my-container-name

You can run the container normally, -p 8000:8000 maps the host port 8000 to the container port 8000 so that you can access it using localhost:8000, or from other machine using your computer’s IP/hostname

Without mapping the ports, you’ll only be able to access it internally, using other containers in a shared network

If you want a simpler command, you can use Docker compose (doc) with a compose file, which holds the settings.

1 Like