简体   繁体   中英

Connect to docker service name from host machine

Let's say I have 2 services defined in my docker-compose.yml like that

# Service app
app:
  networks: 
    - backend
 # Service server
server:
  networks:
    - backend
  ports:
    - 80:80

The app service will upload data on the server service by requesting http://server:80/ and it will display the data url http://server:80/data

Now from my browser I want to click that link but I can't access the server via it's docker hostname, I can only access it via http://localhost:80/data .

Is there anyway to configure my docker-compose to map the hostname server outside of docker so it's accessible from my host machine ?

No.

You will have to update your hosts file /etc/hosts ( C:\\Windows\\System32\\Drivers\\etc\\hosts on Windows) with an entry similar to below:

127.0.0.1   localhost server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM