I am working on a Django project, & I am using Docker Compose to set up and run a simple Django/PostgreSQL app. The problem is when I try to run the command "docker-compose up" the terminal gives me the URL to run on the browser but nothing happening in the browser. Can you help me if you have any idea, I will be so thankful.
Dockerfile:
FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
Docker-compose.yml:
version: '3'
services:
web:
build: .
command: python src/products_projects/manage.py runserver 192.168.99.100:8000
volumes:
- .:/code
ports:
- "8000:8000"
redis:
image: "redis:alpine"
The Docker Terminal:
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com
$ docker-machine ip
192.168.99.100
The results in the terminal:
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | August 31, 2020 - 11:44:23
web_1 | Django version 3.1, using settings 'products_projects.settings'
web_1 | Starting development server at http://192.168.99.100:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | Error: That IP address can't be assigned to.
productsrestapidocker_web_1 exited with code 1
enter image description here
The containers that are deployed with the compose file that you shared are using the docker-bridge network and have their own IP addresses.
The python src/products_projects/manage.py runserver
is executed from the container perspective, which has its own IP address, different than the docker-machine IP address.
The runserver
command starts a lightweight development Web server on the local machine(inside the container in this case). By default, the server runs on port 8000 on the IP address 127.0.0.1.
The ports:
option that you are using in the compose file creates a DNAT rule from the docker-machine to the container. This means that you can start the Django web server simply without specifying the IP argument and port, or if this will not work, you may try to replace 192.168.99.100:8000
with 0.0.0.0:8000
.
Then, the site should be accessible in the browser at 192.168.99.100:8000
, the request being translated to the container IP address on port 8000, where the web-server is listening and accepting connections.
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