Docker run error: website can't be open, server error

Hello, I am pretty new on docker, I try now with command on terminal my web-app …but it gives error , it says that Safari can’t be open the website, server is overloaded, try again later…
but it give later the same error too.

my command is:

docker run -p 5000:5000 --volume=/User/dogacetinkaya/Desktop/pexonhwdockerfilekopie:/app pexonhwdoga

if u can help me to find my mistake, I ll be very thankful…

Doga C.

Hi

What is “pexonhwdoga” ?

it needs to be an image name

I did it with
$ docker build -t pexonhwdoga .
as an image name…

what should I take ?

fair enough.

Find the container id or name by running: docker ps -a, and try and see if it posted any logs before it quit with: docker logs ID/NAME

What we really need to know is what is inside your Dockerfile to see how you started your web site.

What network adapter is your site listening on? If it’s 127.0.0.1:5000 that’s your problem. The site is listening on localhost which is why it can’t be seen outside of the container. You need to bind your web site to 0.0.0.0:5000 so that it’s listening on all network adapters. Then it can be reached from outside of the container.

1 Like

hi, first of all , thx for the answer.
my docker file is:

Dockerfile, Image, Container

FROM python:3.8-slim

#convention to create an environment variable

#it will set the value this environment variable to 1

RUN pip install --upgrade pip

#copy everything to this expected /code going to be created within oour container

# copy the requierements.txt and installing each of the dependency on this container

#it will be copied in /code/

COPY ./requirements.txt /app/requirements.txt

EXPOSE 80

#working directory

WORKDIR /app

#we want to make sure that each of our dependencies are going to be installed in our container

RUN pip install -r requirements.txt

#copy the entire project to the directory that we have created

COPY . /app

#entrypoint of our container

CMD ["python", "app.py"]

an my docker-compose.yml :

version: '3'
services:
  web:
    build: .
    ports: 
      - "80:80"
    volumes:
    - .:/app:/Desktop/pexonhwdockerfilekopie/app.py
  redis: 
    image: redis

and main :

if __name__ == '__main__':
   app.run(host='0.0.0.0', port=80)

and now if I run it with “docker compose up”, then it gives two url which are
http://127.0.0.1:80 and http://172.20.0.3:80
127… is running but 172… takes a little bit and says that website can’t be open…

and if I run it over app.py with “python3 app.py”, then it gives:

  • Running on http://127.0.0.1:80
  • Running on http://192.168.178.48:80 (Press CTRL+C to quit)
    so both of them is running correctly.

finally i didn’t understand where am I doing mistake

i am very thankful if u can help me…

When you run locally, 192.168.178.48:80 is the IP address and port on your local computer. I’m guessing you are using Docker Desktop which is creating a Linux VM in the background and the 172.20.0.3 is the IP address of that Linux VM which is why you can’t reach it from your local computer.

2 Likes

thx for your answer…
yes I have a docker desktop…
now I understand why it does not work.

thank u sooo much…:slight_smile:

@dogacet I edited your post. Please, follow tips in the following post next time to help us by making your post more readable and get an answer more quickly.

Luckily for you, @rofrano gave you great advice even without formatting. I just want to add clarify some possible misunderstaning.

Actually both 127.0.0.1 and 172.20.0.3 is an IP address inside the container. 127.0.0.1 works, because of port forwarding. In other words: publishing port 80. Then host machine has its own loopback IP 127.0.0.1 and port 80 is forwarded from that IP into the container in the virtual machine. One of the jobs of Docker Desktop is to forward ports from the host to the virtual machine, so Docker inside that VM can forward the port from the VM into the container. The IP address 172.20.0.3 does not exist on the host machine, because that belongs to a local, private interface inside the VM. That is why it doesn’t work. Applications running inside the container do not know anything about the IP addresses of the host machine, at least not in case of Docker Desktop, so you can’t rely on the information shown in the containers’ console.

You’re welcome. While it’s nice that Docker Desktop gives you the illusion that Docker is running natively on your Mac or Windows computer, it’s important to understand that it is not and there is a hidden Linux VM that’s actually running Docker. Glad I could help.

hi, i understood now.

this is my project on GitHub , can u maybe run it at once. i want to know if it is running on any other computer?

thx very much…

I did and It doesn’t work on another computer for several reasons. First you have hard coded the path: /Desktop/pexonhwdockerfilekopie/app.py into your docker-compose.yml file. That path does not exist on my computer. I’m not sure why you felt you needed it. The volume .:/app already shares your current folder inside the container as /app. Just remove it.

When I removed that, the next error I get is:

TemplateNotFound
jinja2.exceptions.TemplateNotFound: index.html

Because Flask templates should be in a ./templates folder by default. Your repo has no folders. Everything is in the root including compiled python .pyc files that should not be checked into GitHub. You should always create a .gitignore file for the language you are using so that these compiled files are not checked in. GitHub will prompt you to create one when you create the repo. You should always allow it to do this.

However, from your compiled Python files I can see that you were using Python 3.10 on your computer but your Dockerfile is using Python 3.8. You always want to use the same version of Python in all of your environments for “Dev/Prod parity” so I would update your Dockerfile to use python:3.10-slim

Once I created a ./templates folder and moved the *.html files into it, the application worked! :smiley:

Finally, I’m not sure why your docker-compose.yml file is running redis since you are not using it. I realize that you are just learning Docker. I would replace redis with postgres since you are using SQLAlchemy and then configure your app to use PostgreSQL instead of SQLite. That would be a good next step for you.

This is a good first attempt at learning Docker. You are well on your way to understanding it.

thx thx thx very much, u gave me so helpful infos, I will immediately make Changes.
u are right, i learn very first time docker and co.
and that is my first project with python. but I have fun doing it. and I m so thankful of u…

You’re welcome. As long as you’re having fun… that’s what really counts. :smiley: