I'm trying to run a bokeh server within a Docker container but bokeh doesn't allow me to enter commands while the server is running. Is there a way to run the server detached so that I can enter other commands while the page is up? I'm using a (slightly modified) ubuntu image with python3 for this container.
If anyone happens to also know why I wouldn't be able to access the page from my host machine after exposing the ports that'd be even better-that's the larger issue I'm trying to solve.
You can use this line:
bokeh serve --show --allow-websocket-origin=localhost:5006 file_name.py
Put the following at the end of the dockerfile to run the command above and be able to access the app your trying to host:
CMD ["bokeh","serve","--show","--allow-websocket-origin=localhost:5006","file_name.py"]
Related
I recently followed the following tutorial to try to debug python code in a Docker container using VSCode:
https://www.youtube.com/watch?v=qCCj7qy72Bg&t=374s
My Dockerfile looks like this:
FROM ubuntu as base
#Do standard image stuff here
#Python Debugger
From base as debugger
RUN pip3 install debugpy
ENTRYPOINT ["python3","-m","debugpy","--listen","0.0.0.0:5678","--wait-for-client"]
I have alternately tried copying the tutorial exactly and using the following ENTRYPOINT instead:
ENTRYPOINT ["python3","-m","debugpy","--listen","0.0.0.0:5678","--wait-for-client","-m"]
I have also configured a VSCode remote attach debug instance to launch.json:
{"name":"Python: Remote Attach","type":"python","request":"attach","connect":{"host":"5678","port":5678},"pathMappings":[{"localRoot":"${workspaceFolder}","remoteRoot":"."}]},
I want the debugger to either debug the current file alone in isolation, or run a file I use to run the entire project, called init.py with the debugger in the docker container.
Currently, when I build and run the docker container with
docker run -p 5678:5678 CONTAINERNAME python3 /home/init.py
It hangs and times out on the Visual Studio side.
In the video, he uses this to run the python unittest module, which is why I tried taking out the -m from the end of the command in my modified version. However, it looks like debugpy doesn't know what to do. I have tried running the docker instance before the remote debugger, or the remote debugger after the docker instance, but the error remains and the debug does not work. How can I remote debug into a docker instance using VSCode?
EDIT:
Thank you FlorianLudwig for pointing out that my original code used commas for the IP rather than the periods required.
I have edited the question to reflect this change. It removed issues where python complained about a malformed address, but it seems I am still having some sort of connection issue to the debugger.
EDIT2:
I think I figured out what caused the connection issue. It appears the visual studio default is to use the same host as the port number in question. I changed my host to 0.0.0.0 and I was able to debug by running the container then connecting to it via Visual Studio Debugging.
In your Dockerfile:
"0,0,0,0:5678" should be "0.0.0.0:5678"
To make it a valid ip address. 0.0.0.0 basically means "any" ip address.
I am running succesfully a django app that is hosted inside a docker container. I change something on my code on purpose in order for my code to break. What I need is somehow to see the log of the running code as if I was running this locally on my computer. For example I forgot to import a library and when I run this locally I get a message on the terminal like "ModuleNotFoundError: No module named 'somemodule'". But when i run the same code from inside the container I get no log, just the container fails to start.
My question is: How can I get a log for my script from inside the container, so I can debug my code?
So, what I wanted to do was to somehow debug/run my own python code that was inside a container in order to see the log of my code.
I managed to do it using VSC and Remote SSH and Remote - Containers extensions.
Remote SSH
Remote - Containers
If the containers are hosted locally on your PC, you dont need the Remote - SSH extension
I'm currently running a locally hosted website, created in flask as part of a project. I wanted the server to be externally visible, so I checked the docs, and found this:
If you run the server you will notice that the server is only
accessible from your own computer, not from any other in the network.
This is the default because in debugging mode a user of the
application can execute arbitrary Python code on your computer.
If you have the debugger disabled or trust the users on your network,
you can make the server publicly available simply by adding
--host=0.0.0.0 to the command line:
$ flask run --host=0.0.0.0 This tells your operating system to listen
on all public IPs.
I assumed the same applied to python, and when started the server like this
if __name__ == "__main__":
app.debug=True
app.run(host='0.0.0.0')
When running this the terminal said Running on http://0.0.0.0:5000/, however clicking on that link just gave a "this site can't be reached" error. I tried to go the default address that it normally directed to (127.0. ...) and although this launched the site on my laptop (where flask is running) I still couldn't access the site from other devices on the same network, even when copy-pasting the url.
I also tried typing my laptops ipv4 (192.168. ...) followed by :5000 but still was unable to connect to the server.
What have I done wrong?
Run this in your terminal:
sudo ufw allow 5000
I have a remote machine at my workplace, when we developers run server/ or docker containers. everything was working fine but a while back somethign went wrong.
if I run the python flask app
from app import app
app.run(host='0.0.0.0', port=5050)
i get message
* Running on http://0.0.0.0:5050/
and I am able to access the above from my local machine using the remote server machine ip:5050 but if I run docker container docker run -itd <conta_image_name> -p 80:90 --add-host=localdomain.com:machine_ip_address i get error message saying IPv4 forwarding is disabled. Networking will not work.
Now this issue is in production so I really need someone to throw up some light, what might be wrong or let me know what more info I need to put.
I have fixed this issue myself following this: https://success.docker.com/article/ipv4-forwarding
Another solution is..
Try adding -net=host along with docker run command
https://medium.com/#gchandra/docker-ipv4-forwarding-is-disabled-8499ce59231e
I am trying to do
http://containertutorials.com/docker-compose/flask-simple-app.html
I have copied the tutorial verbatim, except I changed
From flask import Flask
to
from flask import Flask
I can built it just fine. I can start it and get the following when I run docker ps from the command line
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
291c8dfe5ddb whatever:latest "python app.py" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp sick_wozniak
I am building this on OSX
I have tried the following
Looking at this post Deploying a minimal flask app in docker - server connection issues
Running $ python app.py to make sure it works without docker
Creating a django project and a dockerfile for that project. Then build, run and access.
So I am confident that docker is working and flask is working independently of each other, but I cannot get them to work together.
If on Linux, then http://localhost:5000 should work seeing as the container is both running and listening on port 5000.
Otherwise, you would be using Docker Machine, and so you need to get the IP of the docker virtual machine using docker-machine ip. On OSX, for example
$ open http://$(docker-machine ip default):5000