How do I set hostname in docker-compose?

后端 未结 8 2210
清酒与你
清酒与你 2020-11-29 18:11

In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?

dns:
  image: phensle         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 18:51

    The simplest way I have found is to just set the container name in the docker-compose.yml See container_name documentation. It is applicable to docker-compose v1+. It works for container to container, not from the host machine to container.

    services:
      dns:
        image: phensley/docker-dns
        container_name: affy
    

    Now you should be able to access affy from other containers using the container name. I had to do this for multiple redis servers in a development environment.

    NOTE The solution works so long as you don't need to scale. Such as consistant individual developer environments.

提交回复
热议问题