What I am unable to do:
Can ping the default docker network's gateway ip from the Ubuntu container, but cannot ping the container from the host machine, I have tried looking at here but this is something the other way round. I want to access my container from my host machine.
What I have tried
So I created a custom network using this:
docker network create --driver=bridge --subnet=192.168.0.1/24 --ip-range=192.168.0.130/24 --gateway=192.168.0.1 br0
This is the newly added network
$ docker network ls
NETWORK ID NAME DRIVER
38bcca85e37a bridge bridge
202ace7d3e0c none null
512b3a6dc77f host host
d5f4b00e3281 br0 bridge
and verified through the inspect command:
$ docker network inspect br0
[
{
"Name": "br0",
"Id": "d5f4b00e3281c27e6d5879ac37463b6d8af728944dc7d3fbc23c25092020c7c7",
"Scope": "local",
"Driver": "bridge",
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.0.1/24",
"IPRange": "192.168.0.130/24",
"Gateway": "192.168.0.1"
}
]
},
"Containers": {},
"Options": {}
}
]
and then ran my container using the following command:
docker run -i -d --name=rc --net br0 --ip 192.168.0.150 -v /var/log/restcomm/:/var/log/restcomm/ -e STATIC_ADDRESS="192.168.0.150" -e ENVCONFURL="https://raw.githubusercontent.com/RestComm/Restcomm-Docker/master/scripts/restcomm_env_locally.sh" -p 80:80 -p 443:443 -p 9990:9990 -p 5060:5060 -p 5061:5061 -p 5062:5062 -p 5063:5063 -p 5060:5060/udp -p 65000-65050:65000-65050/udp restcomm/restcomm:latest
then I logged on to the running container and ran the ifconfig command
$ docker exec -it a09a4c120999 bash
root@8412c266634d:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:c0:a8:00:96
inet addr:192.168.0.150 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::42:c0ff:fea8:96/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 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:508 (508.0 B) 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:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:142 (142.0 B) TX bytes:142 (142.0 B)
root@a09a4c120999:/# exit
The problem here is still that even the IP of this container is set to be 192.168.0.150 but it is still unable to ping the host machine whose IP is 192.168.0.115. Also the above command I have to run quickly, as you can see the container exits by itself, so i restart the container again and again to try and run a single command, if I try to login in again without restarting, it gives the following error:
$ docker exec -it e0783d69b96f bash
Error response from daemon: Container e0783d69b96f8e7ff4a17f76d0066b78c4b54a6817de7526a514f42a6af4640e is not running: Exited (1) 1 seconds ago
I verified this also by listing all the containers
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e0783d69b96f restcomm/restcomm:latest "/sbin/my_init" 5 minutes ago Exited (1) 4 minutes ago rc
I am running docker on windows 10 and followed these instructions from here
Edit: The container exits itself after I add this custom network, so probably there is something wrong in trying to add the network, but this command i have found in their official tutorial from here
So there are 2 problems
- Even though I can specify the IP I want I am still unable to ping to and from the container and host
- The container exists itself after I add the custom network
EDIT:
Thanks to @VonC I fixed the second problem by adding the recommended switch, yes these two are not related