What should I do if docker cannot access the host after changing its IP address?

angryTom
Release: 2020-03-16 11:54:28
Original
4137 people have browsed it

What should I do if docker cannot access the host after changing its IP address?

What should I do if docker cannot access the host after changing the IP address?

Problem description

When creating a container Use the -p option to specify the port 8000 opened by the container (recommended learning: jQuery video tutorial)

Start in the Docker container with the command python manage.py runserver Django server

Use the docker ps command to get the IP mapping from the host to the container0.0.0.0:32564

Then access the address through the browser on the hostlocalhost :32564

The result is that Django in the container cannot be accessed

Solution

The command python manage.py runserver defaults to listening on 127.0.0.1 :8000

But the address 127.0.0.1 is a loopback address, which means "myself" and cannot be accessed externally. It can only be accessed by myself

So you need to specify the listening portpython manage. py runserver 0.0.0.0:8000, where 0.0.0.0 means listening to all addresses

and then use the host's browser to access the address localhost:32564, which is mapped to the container's localhost:8000

For more related tutorials, please pay attention to the docker tutorial column on the PHP Chinese website.

The above is the detailed content of What should I do if docker cannot access the host after changing its IP address?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template