0

Monday when I got to work I realized that Docker was something that I had to use to fix some server issues in the company at the moment. So since this week all my work has been studying Docker and try to make it work as soon as possible.

So far I understood the containers / swarm / etc, but I am still stuck with the network. Basically I need to run 3 different networks under Docker with different containers on it.

Check image example here please

I need to run 3 different networks which will be assigned to 3 public IPs provided by the hoster (OVH) (I don't even know if it will work since only tomorrow I'll get the VPS to work).

So let's say over the network 1 there will be 3 containers to be used as production, network 2 will be used for development and 3rd network to be used as test.

Is this possible to make with Docker?

ATM I'm running tests on a raspbian (jessie) using Docker engine but like I said, I am still stuck with the whole Docker network interface.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Diogo Jesus
  • 318
  • 4
  • 19
  • will all the containers run on a single host server? – Webert Lima Mar 30 '17 at 13:41
  • yes, i only got one server to work it, so the idea is to "virtualise" (in some way) my VPS – Diogo Jesus Mar 30 '17 at 13:44
  • i don't get you mean by assigning a pulic IP addr to a network. you can assign an IP to a container though. – Webert Lima Mar 30 '17 at 13:50
  • when we ordered the new VPS at OVH we also bought 4 IPs to be used inside, so the idea is to have an IP for each network and 1 IP for the server it self – Diogo Jesus Mar 30 '17 at 13:52
  • alright but it doesn't make sense to me when you say you have an IP for the network. Usually a network has a range of IPs. – Webert Lima Mar 30 '17 at 13:54
  • ok, so from your perpective it doesn't work (which it can be possible since i'm into this for only 4 days, so i'm trying to see all the possibilities), you also said above that i can add an IP to the container itself, that might be interesting to know about, i did some researches about it but without any success. Could you please link some tutorials on how to add for example external IPs to the containers? (i'm not looking into port forward) – Diogo Jesus Mar 30 '17 at 14:01
  • I think if you run it with --net=host and --ip=ip_addr it might work. see the answer I've posted below, too. – Webert Lima Mar 30 '17 at 14:17

1 Answers1

1
  • Create the networks

    docker network create net1
    docker network create net2
    docker network create net3
    
  • Attach the containers to the desired network

    docker run --net=net1 --name=container1 [opts] [image]
    

or, if the container already exists:

docker network connect net1 container1

if you to attach a host IP to the container you can just bind a port to it. Let's say a container runs o port 80:

docker run --name=container1 --net=net1 -p YOU_IP_ADDR:80:80 [image]
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Webert Lima
  • 13,197
  • 1
  • 11
  • 24
  • "if you to attach a host IP to the container you can just bind a port to it. Let's say a container runs o port 80:" is there a way to add ports over a existing container? or does i have to delete the actual container to open the port? – Diogo Jesus Mar 30 '17 at 14:26
  • 1
    This is much easier to do with compose – Software Engineer Mar 30 '17 at 14:35
  • @DiogoJesus as far as I know the best way is to remove the existing container and recreate it. They're build for this, to die and born easily. – Webert Lima Mar 31 '17 at 13:24