Docker Container Networking with Docker-in-Docker

前端 未结 3 561
傲寒
傲寒 2021-02-04 01:35

I would like to network with a child docker container from a parent docker container, with a docker-in-docker setup.

Let\'s say I\'m trying to connect to a simple Apache

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 01:56

    I am very convinced that @Yuriy Znatokov's answer is what I want, but I have understood it for a long time. In order to make it easier for later people to understand, I have exported the complete steps.

    1) From inside the docker:dind container

    docker run -d --name mydind --privileged docker:dind
    / # docker run -d -p 8080:80 httpd:alpine
    / # curl localhost:8080
    

    It works!

    2) From inside the docker:latest container

    docker run -d --name mydind --privileged docker:dind
    docker run -it --link mydind:docker docker:latest sh
    / # docker run -d -p 8080:80 httpd:alpine
    / # curl mydind:8080
    

    It works!

提交回复
热议问题