Skip to content

Commit

Permalink
Fix docker env
Browse files Browse the repository at this point in the history
  • Loading branch information
vanpelt authored Apr 3, 2024
1 parent d7bb757 commit 7a2318e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can build and run the docker file from the `/backend` directory:

```bash
docker build . -t wandb/openui --load
docker run -p 7878:7878 -e OPENUI_ENVIRONMENT=prod -e OPENAI_API_KEY wandb/openui
docker run -p 7878:7878 -e OPENAI_API_KEY wandb/openui
```

Now you can goto [http://localhost:7878](http://localhost:7878)
Expand Down
20 changes: 18 additions & 2 deletions backend/openui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@
from .logs import setup_logger
from . import server
from . import config
import os
import uvicorn
from uvicorn import Config
import sys

def is_running_in_docker():
# Check for the .dockerenv file
if os.path.exists('/.dockerenv'):
return True

# Check for Docker-related entries in /proc/self/cgroup
try:
with open('/proc/self/cgroup', 'r') as file:
for line in file:
if 'docker' in line:
return True
except Exception as e:
pass

return False

if __name__ == "__main__":
ui = any([arg == "-i" for arg in sys.argv])
Expand Down Expand Up @@ -33,7 +49,7 @@
api_server = server.Server(
Config(
"openui.server:app",
host="0.0.0.0" if config.ENV == config.Env.PROD else "127.0.0.1",
host="0.0.0.0" if is_running_in_docker() else "127.0.0.1",
log_config=str(config_file) if ui else None,
port=7878,
reload=reload,
Expand All @@ -52,7 +68,7 @@
# work with the uvicorn.run approach, so here we are
uvicorn.run(
"openui.server:app",
host="0.0.0.0" if config.ENV == config.Env.PROD else "127.0.0.1",
host="0.0.0.0" if is_running_in_docker() else "127.0.0.1",
port=7878,
reload=reload,
)
Expand Down

0 comments on commit 7a2318e

Please sign in to comment.