📜  使用容器名称从主机访问 docker 容器 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:42.881000             🧑  作者: Mango

代码示例1
Access docker container from host using containers name



$ cat docker-compose.yml
version: '3'
services:
  nginx-1:
    image: nginx
    hostname: nginx-1.docker
    network_mode: bridge 
  linux-1:
    image: alpine
    hostname: linux-1.docker
    command: sh -c 'apk add --update bind-tools && tail -f /dev/null'
    network_mode: bridge # that way he can solve others containers names even inside, solve nginx-2, for example