Docker Community Forums

Share and learn in the Docker community.

Help needed - Connecting the container to the outside network


(Gtmanfro) #1

Hello!
I’m new on the docker world and I need some help to configure my docker to connect the containers to the outside network.

Here’s my situation:

I’m building an image (using docker version 1.12.1) based on Ubuntu with oracle database and samba installed.

My problem:

I need to have direct access between my workstations and the containers. Basically I’m trying to make the containers assume an IP from the outside network, this way the workstation will be able to see the container and any directory shared by it’s samba. I need the samba share because my files are strongly attached to the database, they must ‘walk’ together. Also I’ll have multiple containers running at same time.

I already tryed to create a specific network using the same subnet that my workstation uses:
docker network create --subnet 172.16.0.0/16 --ip-range=172.16.0.0/16 --gateway 172.16.1.1 mynetwork

Then I run the container using my network:
docker run -it --net mynetwork --ip 172.16.15.10 myimage /bin/bash

Now i’m inside the container, but there is no communication with my workstation.

Heres the ifconfig output of my container:

root@f053501:/# ifconfig

eth0 Link encap:Ethernet HWaddr 02:42:ac:10:0f:0a
inet addr:172.16.15.10 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe10:f0a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1016 (1.0 KB) TX bytes:508 (508.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ifconfig from the host:

[root@docker ~]# ifconfig
br-5540c3a43e12 Link encap:Ethernet HWaddr 02:42:FE:24:3D:ED
inet addr:172.16.1.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:feff:fe24:3ded/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:254525 errors:0 dropped:0 overruns:0 frame:0
TX packets:450342 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13962970 (13.3 MiB) TX bytes:700004792 (667.5 MiB)

docker0 Link encap:Ethernet HWaddr 02:42:C8:E9:EC:4F
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:c8ff:fee9:ec4f/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:254525 errors:0 dropped:0 overruns:0 frame:0
TX packets:450342 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13962970 (13.3 MiB) TX bytes:700004792 (667.5 MiB)

eth0 Link encap:Ethernet HWaddr 00:0C:29:3C:12:E8
inet addr:172.16.1.48 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fe3c:12e8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:106700383 errors:1755 dropped:15956 overruns:0 frame:0
TX packets:2066691 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13704731046 (12.7 GiB) TX bytes:512656040 (488.9 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:73 errors:0 dropped:0 overruns:0 frame:0
TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:10581 (10.3 KiB) TX bytes:10581 (10.3 KiB)

veth2e9dbae Link encap:Ethernet HWaddr 6E:18:B4:7C:CC:09
inet6 addr: fe80::6c18:b4ff:fe7c:cc09/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:900 (900.0 b) TX bytes:1296 (1.2 KiB)

Any ideias?
Thank you!