clayton groth
clayton groth

Reputation: 308

Adding/Exposing a port with Django to an existing Docker container

This may have a fairly simple answer here, but...

I am trying to use this container: https://hub.docker.com/r/gboeing/osmnx in order to just easily handle some complex dependencies. I ran into all kinds of conda dependency issues with the library I'd like to use when just building a docker image from the continuum/anaconda container.

So, I'd like to expose a port and run a Django server from inside this container.

I manually installed Django and ran the server inside the container. However, I cannot connect to localhost, http://127.0.0.1:8000/.

(base) root@91805d36444c:/server# python manage.py runserver 
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
May 27, 2020 - 05:31:45
Django version 3.0.6, using settings 'server.settings'
Starting development server at http://127.0.0.1:8000/

Navigating to http://127.0.0.1:8000/ in the browser, cannot be reached.

Possibly relevant info:

Upvotes: 1

Views: 934

Answers (2)

clayton groth
clayton groth

Reputation: 308

Turns out I was in the wrong conda environment for just installing osmnx on a fresh container FROM continuum/anaconda I missed this part:

#
# to activate this environment, use
#
# conda activate ox
#
...
$(base) root@faa8a6b1c8d0:/# conda activate ox
$(ox) root@faa8a6b1c8d0:/# 

Additionally, the gboeing/osmnx:latest container has a jupyter notebook on the same port I was trying to access.

Starting fresh and working now!

Upvotes: 0

Panagiotis Simakis
Panagiotis Simakis

Reputation: 1257

You have to publish the desired port using the -p parameter.

docker run -p 8000:8000 gboeing/osmnx:latest

and then run django app:

python manage.py runserver 0.0.0.0:8000

More details here

Upvotes: 2

Related Questions