Reputation: 323
I have a backuppc local service running e.g. 127.0.0.1:8081 . I can also reach it directly on http://172.23.0.4 (container ip)
docker-compose.yml
version: '3.7'
services:
backuppc-app:
image: tiredofit/backuppc
container_name: backuppc-app
ports:
- "8081:80"
- "8082:10050"
environment:
- BACKUPPC_UUID=1000
- BACKUPPC_GUID=1000
restart: always
depends_on:
- backuppc-mysql
networks:
- nginx-proxy
I want to assign it a hostname, something like
hostname: backup.local
I tried to add it but doesn't work as expected
backuppc-app:
image: tiredofit/backuppc
container_name: backuppc-app
hostname: backup.local
Should I manually edit my local /ets/hosts ?
172.23.0.4 backup.local
Upvotes: 0
Views: 195
Reputation: 20176
You can add a hostname as a network alias:
version: '3.7'
services:
backuppc-app:
networks:
nginx-proxy:
aliases:
- backup.local
For containers in nginx-proxy
network it will be available both as backuppc-app
and as backup.local
.
If you want that hostname to be visible to your host you need to modify hosts file. But don't put container IP there - it can change. Rather add it as another name for localhost:
127.0.0.1 localhost myhostname backup.local
Then you can access it both with localhost:8081
and backup.local:8081
(that works due to port forwarding you've declared with ports:
key).
Upvotes: 1