Difference between links and depends_on in docker_compose.yml

前端 未结 3 1085
-上瘾入骨i
-上瘾入骨i 2020-12-04 05:01

According to the Docker Compose\'s compose-file documentation:

  • depends_on - Express dependency between services.
  • links - Lin
3条回答
  •  独厮守ぢ
    2020-12-04 05:18

    The post needs an update after the links option is deprecated.

    Basically, links is no longer needed because its main purpose, making container reachable by another by adding environment variable, is included implicitly with network. When containers are placed in the same network, they are reachable by each other using their container name and other alias as host.

    For docker run, --link is also deprecated and should be replaced by a custom network.

    docker network create mynet
    docker run -d --net mynet --name container1 my_image
    docker run -it --net mynet --name container1 another_image
    

    depends_on expresses start order (and implicitly image pulling order), which was a good side effect of links.

提交回复
热议问题