-1

I have created my docker image and container using the Dockerfile in this blog. https://hackernoon.com/raspberry-pi-cluster-emulation-with-docker-compose-xo3l3tyw

I am able to ssh into the rpi and ifconfig returns the following status:

pi@raspberrypi:~ $ ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        ether 52:54:00:12:34:56  txqueuelen 1000  (Ethernet)
        RX packets 561  bytes 49862 (48.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 386  bytes 47311 (46.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 41  base 0x1000    dma 0xff

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2  bytes 100 (100.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 100 (100.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Now I want to be able to connect this to internet. As per docker docs, I tried to connect a running container to the internet using:

docker network connect multi-host-network 008796f5316a

It returns the error. Error response from daemon: network multi-host-network not found.

How can I connect to the internet from inside the docker?

Edit: The blog talks about running qemu on docker and installing a modified raspbian on top of that(for compatibility with qemu). When I access the container using docker exec command,

docker exec -it testnode bash

ifconfig returns the following:

root@1f210520938c:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 637  bytes 356778 (356.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 404  bytes 39482 (39.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

And the ifconfig command for pi returns the results as shown above. So, ping google.com is working on the root@ and not on pi@raspberry.

I need to connect the pi directly to the internet.

Jatin Sharma
  • 29
  • 2
  • 8

2 Answers2

1

This error occurs because you haven't created a Docker network called multi-host-network. To create it, you may refer to Docker docs.

By default, all docker containers are connected to the default bridge network (the name matches driver type). As for docker-compose, bridge network with name docker-compose-directory-name_default will be created, as described here. You can check it by running docker network inspect docker-compose-directory-name_default and find your container in Containers section.

Since your container is already connected to the internet, it should have internet access without explicitly connecting it to a network.

If there is no internet connection, please try other solutions proposed in this question. I would suggest starting with

sysctl -w net.ipv4.ip_forward=1 # both on host and container
sudo service docker restart # (or sudo systemctl restart docker) on host
Robert
  • 3
  • 3
geobreze
  • 2,274
  • 1
  • 10
  • 15
0

The instructions you're following set up QEMU to use "user-mode networking". This is (sort of) like QEMU itself emulating a little NAT-router and private network that the VM lives behind. This in turn is inside the docker container and talking to whatever the docker container's networking setup is, so you have two layers here -- you'll want to be clear about this double-layer setup so you don't get confused about which of the two might be the source of any problems you have.

User-mode networking has some limitations: notably, ping doesn't work, and you can't connect from the outside into the VM except where you have specific port-forwarding set up (the instructions include a port-forward from host port 2222 to the VM's ssh port 22).

So you need to figure out whether you can live with user-mode networking's limits, and make sure that whatever testing you're doing is testing what you care about and not things you probably don't really care about like whether ping packets in particular work. If you don't want user-mode networking, you'll need to set up a QEMU tap (bridge) network backend, which is a lot more complicated but does let you make a QEMU VM truly visible as a machine on the host network.

Peter Maydell
  • 9,707
  • 1
  • 19
  • 25