How do I set up linkage between Docker containers so that restarting won't break it?

前端 未结 11 2259
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 05:40

I have a few Docker containers running like:

  • Nginx
  • Web app 1
  • Web app 2
  • PostgreSQL

Since Nginx needs to connect to the

11条回答
  •  青春惊慌失措
    2020-12-02 06:07

    You may use dockerlinks with names to solve this.

    Most basic setup would be to first create a named database container :

    $ sudo docker run -d --name db training/postgres
    

    then create a web container connecting to db :

    $ sudo docker run -d -P --name web --link db:db training/webapp python app.py
    

    With this, you don't need to manually connect containers with their IP adresses.

提交回复
热议问题