Do I need to create multi host network in docker?

一个人想着一个人 提交于 2019-12-13 11:05:07

问题


For the below docker-compose building docker file dynamically:

version: '2'

volumes:
  jenkins_home:
    external: true

services:
  jenkins:
    build:
      context: .
      args:
        DOCKER_GID: ${DOCKER_GID}
        DOCKER_ENGINE: ${DOCKER_ENGINE}
        DOCKER_COMPOSE: ${DOCKER_COMPOSE}
    volumes:
      - jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "8080:8080"

creates bridge type network (project1_default) is created:

$ docker network ls
NETWORK ID          NAME                     DRIVER              SCOPE
....
f1b7ca7c6dfe        project1_default         bridge              local
....

after running below command:

$ docker-compose -p project1 up -d

After launching and connecting to master jenkins, we configure and create slave jenkins on separate EC2 host using EC2 plugin of master jenkins.

But, above network (project1_default) is single host network, that can allow packets travel within single host. Below is my visualisation of bridge type network (project1_default)...

So, we need to launch and configure master jenkins to launch a slave jenkins on separate EC2 hosts using EC2 plugin,


  1. Do I need to create multi-host network(swarm) type? instead of bridge type (project1_default)...

  2. If yes, how to create a multi-host network?


回答1:


all three should run in a container? Plus the containers are running on separate ec2 instances, correct?

you could expose the necessary ports to the underlying host IP. This will expose the Jenkins containers to your network and you will be able to interact with it, just as if it was installed directly on the ec2 instance (and not in a container).

Here an example

docker run -p 80:8080 ubuntu bash

this will expose port 8080 in the container to port 80 on your host machine. Start with your master and then the slaves and add your slaves just as you would in a non-container setup by using the ec2 instance's IP and the port that you exposed for the slaves.

You can find more information regarding port publishing here

  • https://docs.docker.com/engine/reference/commandline/run/


来源:https://stackoverflow.com/questions/58781368/do-i-need-to-create-multi-host-network-in-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!