Using --add-host or extra_hosts with docker-compose

后端 未结 5 2054
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 03:47

I am using docker-compose to run a test environment, that consists of about 5 different containers. The inter-container links and the shared volumes (volumes-from)

5条回答
  •  被撕碎了的回忆
    2021-01-30 04:16

    Basic docker-compose.yml with extra hosts:

    version: '3'
    services:
    api:
        build: .
        ports:
            - "5003:5003"
        extra_hosts:
            - "your-host.name.com:162.242.195.82" #host and ip
            - "your-host--1.name.com your-host--2.name.com:50.31.209.229" #multiple hostnames with same ip
            
    

    The content in the /etc/hosts file in the created container:

    162.242.195.82  your-host.name.com
    50.31.209.229   your-host--1.name.com your-host--2.name.com
    

    You can check the /etc/hosts file with the following commands:

    $ docker-compose -f path/to/file/docker-compose.yml run api bash  # 'api' is service name
    #then inside container bash
    root@f7c436910676:/app# cat /etc/hosts
    

提交回复
热议问题