Search code examples
linuxdockernetwork-programmingdocker-swarmlxc

Do I need to create multi host network in docker?


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)...

enter image description here

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?


Solution

  • 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