Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the app doesn't run locally with port mapping- docker

My problem is when I run my application on a container and map a port, the app does not run on my local machine.


I use ubuntu and here is my dockerfile:

FROM python:3.8.13-alpine3.14

WORKDIR /app/
COPY ./requirements.txt .

RUN apk add -u zlib-dev jpeg-dev gcc musl-dev
RUN python3 -m pip install --upgrade pip
RUN pip3 install -r requirements.txt

COPY . .
ENV API_URL='http://my_api.com'
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "8000"]

when I run the image with the command bellow django app starts in the container.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

docker run -d -p 8000:8000 dj-test

I say that because when I run a shell in this container

docker exec -it  e906801932ac  sh

and I check 127.0.0.1:8000, here is the response:

/app # wget localhost:8000

Connecting to localhost:8000 (127.0.0.1:8000)
saving to 'index.html'
index.html           100% |*****************************************************************************************************************************| 10697  0:00:00 ETA
'index.html' saved

but when I try this in my local machine, the response is different.

wget localhost:8000   
--2022-04-23 18:48:06--  http://localhost:8000/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2022-04-23 18:48:07--  (try: 2)  http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2022-04-23 18:48:09--  (try: 3)  http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2022-04-23 18:48:12--  (try: 4)  http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2022-04-23 18:48:16--  (try: 5)  http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.


when I try docker ps here is the response:

CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                       NAMES

e906801932ac   dj-test   "python manage.py ru…"   29 minutes ago   Up 29 minutes   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp   nice_goldwasser

Can you help me to find the problem here?
Thanks.

>Solution :

You need to replace "8000" instead "0.0.0.0:8000" in the CMD command.

see more:

django change default runserver port

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading