I'm trying to serve django on our local wifi IP, so our client developer can use his iOS device to test the API. The problem is that when I run the containers, it's only accessible from my chrome browser as localhost(=chrome browser run on the same macbook that is used to run the containers)
My docker-compose file:
version: '3'
volumes:
dev_postgres_data: {}
dev_postgres_data_backups: {}
services:
django:
build:
context: .
dockerfile: ./compose/dev/django/Dockerfile
image: apps_dev_django
container_name: django
depends_on:
- postgres
volumes:
- .:/app:z
env_file:
- ./.envs/.dev/.django
- ./.envs/.dev/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: apps_production_postgres
container_name: postgres
volumes:
- dev_postgres_data:/var/lib/postgresql/data:Z
- dev_postgres_data_backups:/backups:z
env_file:
- ./.envs/.dev/.postgres
# ports must be set to use postgres container alone
ports:
- "5432:5432"
If I run the django server locally(=not using docker-compose)with the command python manage.py runserver 192.168.0.255:8000
, the client who is using the same wifi as me can access the API.
I got the 192.168.0.255 with the command ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d -f6
(something I got after some googling).
If I run ifconfig, I get,
...
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether a4:5e:60:f1:cb:5b
inet6 fe80::85:51dd:e37a:5435%en0 prefixlen 64 secured scopeid 0x4
inet 192.168.0.17 netmask 0xffffff00 broadcast 192.168.0.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
...
Is there a way to run the docker-compose on my local wifi, so I can let the client developers who's on the same wifi to access the API?
Thanks.
(Edited)
The following does not seem to work neither :(
Thanks for the help. But this configuration does not seem to work.
```docker
...
services:
django:
...
networks:
lan:
ipv4_address: 192.168.0.10
postgres:
...
networks:
lan:
ipv4_address: 192.168.0.11
networks:
lan:
ipam:
driver: default
config:
- subnet: "192.168.0.0/24"
gateway: "192.168.0.1"
question from:
https://stackoverflow.com/questions/65895823/how-to-make-docker-compose-django-server-run-on-local-wifi-network-so-our-ios-d 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…