I'm running a flask application within a Docker container so I need to bind the host and container port (in this case port 5000 in both).
Running this command:
docker run -v //c/Users/Nicholas/PycharmProjects/flask_tutorial:/opt/project -e "FLASK_APP=/opt/project/flaskr.py" -p 0.0.0.0:5000:5000 flask flask run --host=0.0.0.0
spins up the container and I can access the app at 127.0.0.1:5000 locally on my browser. However after entering these same settings into the Pycharm (2016.2.3) run configuration GUI and starting the container I cannot access the app (I have tried ticking the "Publish all ports" option to no avail):
Using docker inspect container_id
with the command line created container, I get these settings under NetworkSettings:
"Ports": {
"5000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "5000"
}
]
},
However with Pycharm run configuration created container, it doesn't appear to have passed on the port bindings:
"Ports": {},
Is there a way to check the options Pycharm is passing to Docker? Or to make it correctly pass on the port binding options?
I'm on Windows 10 and Docker is running on Hyper-V (not VirtualBox)
Docker containers can connect to the outside world without further configuration, but the outside world cannot connect to Docker containers by default.
By default, the httpd server listens on port 80. It's not mandatory to perform port mapping for all Docker containers. Often, we will avoid opening host ports in order to keep the services of the container private or only visible to sibling containers in the same Docker network.
I had a similar issue with a Django application. Here is how I solved it :
First you need to set up the project interpreter in a docker container :
project interpreter
Docker
,ok
button.Now you need to create a proper run configuration.
ALT+u
ALT+r
ALT+inser
,Flask server
.Docker container settings
, click on this text areaSHIFT+enter
.You will have a menu allowing you to configure multiple docker run parameters including port biding.
For me adding the localhost IP ('0.0.0.0') as arg in the app object run call solved it
app.run(host='0.0.0.0')
I had a similar issue. For me, it worked to change the docker container settings in the Edit Run Configuration menu. If you click on the small folder you can add port and volume mapping.
Maybe it's trivial for most people or is supper clear in the documentation, but it took me a while to find it, so I'm adding this just in case there are more people looking for the port volume mapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With