I'm following a tutorial, using this command in a Docker container to start the Django server:
python3 manage.py runserver 0.0.0.0:8000
But I can not connect to it by IP.
I am sure that I have already open the 8000 port and this port is on listening. By the way, I use the ubuntu and set the server in the aliyun.
At First Django works on port 8000 not on 8080. So you should use python manage.py runserver 0.0.0.0:8000. You can eazly kill port in linux server by type: fuser 8080/tcp
Related
I'm running a django development server in my Debian GNU/Linux host machine with python manage.py runserver.
After running a Debian docker container with
$ docker run -it --add-host=host.docker.internal:host-gateway debian bash
I expected I could make a curl in http://localhost:8000 with
curl http://host.docker.internal:8000
but I get
Failed to connect to host.docker.internal port 8000: Connection refused
Is it something related to running Django with python manage.py runserver?
I'm trying to run my first ever docker. On console everything seems to be fine, but the chrome says connection is refused. It tried to turn off windows firewall - no effect. Running on win10home.
$ docker run -p 8000:8000 -v `pwd`:/data --rm -it mydjango mynewproject/manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
December 28, 2016 - 11:48:20
Django version 1.10.4, using settings 'mynewproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Dockerfile:
From python:3
RUN pip install django
EXPOSE 8000
RUN mkdir /data
WORKDIR /data
I had this issue when running the server with the command
python manage.py runserver 8080
Running the command
python manage.py runserver 0.0.0.0:8080
Fixed it for me. Note the 0.0.0.0
Could you please try adding "docker ip" in the ALLOWED HOSTS in the mynewproject/settings.py
The url you are checking with is "docker-ip":8000 right?
To get docker docker container IP,
You can use docker inspect
Some thing like this:
CID=$(docker run -d -p 4321 base nc -lk 4321);
docker inspect $CID
Run the following command in CMD for Windows OS by going to the directory of your project then execute these commands:
python manage.py migrate #run this command to sync your Database with Django project
python manage.py runserver # run the server on http://127.0.0.1:8000/
For the more tutorial watch this channel simple Tutorials of Django is available
https://www.youtube.com/playlist?list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK
I have also learned from here. If you find your answer a Thumbs up will be appreciated . Happy Coding
I have created the project with command
:: eb create --database.engine postgres --region ap-southeast-1.
It shows that my deployment is successful.
Also when I run command :: eb open, it successfully open my project website.
Also when I checked eb-activity logs on my instance at /var/log/eb-activity.log, it also shows migration successful when I deployed my project.
But When I tried to run $ python manage.py migrate manually on Elastic Beanstalk instance it gives error,
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
Also when I tried to create a user manually on python manage.py shell. It again gives error,
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I want to access postgres database on elastikbeanstalk instance and want to use commands
$ python manage.py migrate.
Is there a way to do that?
This question already has answers here:
Deploying a minimal flask app in docker - server connection issues
(8 answers)
Closed 5 years ago.
I have a flask script which I try to execute it via docker run command. Following command i am doing
docker run -dit -v /media/sf_MY_WINDOWS/GitRepo/:/ext/GitRepo -p 5000:5000 "isbhatt/prefixman:v1" /ext/docker/vm_scripts/db_loader.sh
and db_loader.sh file contains
/usr/local/bin/python2.7 /ext/SDSNG/src/prefix_manager/manage.py runserver --host 0.0.0.0 &
but when I do curl localhost:5000 Connection refused.
If I go into container and run the stuff and do curl localhost:5000 it works in container..
What is wrong here?
Output of netstat -tln on container
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN
If inside your container your script is binding to 127.0.0.1, then the port forwarding normally provided using -p will not work. Ensure that inside the container your service is listening on 0.0.0.0.
You can check on what address your service is listening by running netstat -tln inside the container:
container# netstat -tln
If you see this:
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN
Then that's your problem. You want to see:
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN
Resolved it. By removing & at the end of manage.py runserver --host 0.0.0.0
That & kept the process in the background and if no process is running in foreground the container would stop even if you have provided -d option.
And #Iarsks , Yup the --host has to be 0.0.0.0 .
i want install Django in my VM created with PuPHPpet (Vagrant), then when i start the server with
python manage.py runserver
My project is normally available in 127.0.0.1:8000
But i have unreachable web page, then i try
python manage.py runserver ipvm:8000 and others ports
I have always unreachable web page
So, i have found in this forum
0.0.0.0:8000
And i have again unreachable web page, Why ? How can start my server in my VM ?
You have to forward the port from Vagrant to your local machine. You can add a line like this to your Vagrantfile:
config.vm.network :forwarded_port, host: 8001, guest: 8000
And then run this in the Vagrant VM:
python manage.py runserver 0.0.0.0:8000
And on your host machine, go to http://localhost:8001 to view the webpage.
Run python manage.py runserver 0:8000. It worked for me
You have to forward the port from Vagrant to your local machine.
config.vm.network :forwarded_port, host: 8001, guest: 8000
Yo need to add IP to ALLOWED_HOST in your setting.py file
0.0.0.0 to the ALLOWED_HOSTS in your settings.py
Run Project
python manage.py runserver 0.0.0.0:8000