How to get Docker containers to talk to each other while running on my local host?

前端 未结 3 799
醉梦人生
醉梦人生 2020-12-08 02:53

I have a Webapp running completely locally on my MacBook.

The Webapp has a Front End (Angular/Javascript) and a Back End (Python/Django) which implements a RESTful A

3条回答
  •  春和景丽
    2020-12-08 03:21

    The way to do this is today Docker Networking, which another answer briefly mentioned.

    The short version is that you can run docker network ls to get a listing of your networks. By default, you should have one called bridge. You can either create a new one or use this one by passing --net=bridge when creating your container. From there, containers launched with the same network can communicate with each other over exposed ports.

    If you use Docker Compose as has been mentioned, it will create a bridge network for you when you run docker-compose up with a name matching the folder of your project and _default appended. Each image defined in the Compose file will get launched in this network automatically.

    With all that said, I'm guessing your frontend is a webserver that just serves up the HTML/JS/CSS and those pages access the backend service. If that's accurate, you don't really need container-to-container communication in this case anyway... both need to be exposed to the host since connections originate from the client system.

提交回复
热议问题