This tutorial is deprecated because
it uses ipvlan instead of macvlan, making it not useful for wifi nics it’s about installing docker inside two vms… I have better examples now.
Select Internal networking
according to here, internal networking fully supports broadcast. I suspect bridged will too…
create a virtual machine
install ubuntu 22.04 server edition
update
install helpful tools
sudo apt install -y net-tools
install ubuntu-desktop-minimal
sudo apt install -y ubuntu-desktop-minimal
install docker, ensuring to add docker group to your user.
install vm guest additions prerequisites
sudo apt install -y gcc make perl
install vm guest additions
restart
pull your desired ros2 image. For example:
docker pull osrf/ros:galactic-desktop
shutdown the guest
save a snapshot
create two linked clones, regenerating all network interface ids and MACs.
select “internal network”
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
cat << EOT sudo tee /etc/netplan/00-installer-config.yaml
network:
ethernets:
enp0s3:
addresses:
- 192.168.0.120/24
dhcp4: no
dhcp6: no
version: 2
EOT
mkdir ~/docker
cd ~/docker
cat << EOT >docker-compose.yml
version: '2'
services:
ros:
container_name: ros2
image: osrf/ros:galactic-desktop
hostname: ros-host
domainname: test
networks:
network:
ipv4_address: 192.168.0.121
command: ros2 run demo_nodes_cpp talker
restart: unless-stopped
networks:
network:
driver: ipvlan
driver_opts:
parent: enp0s3
ipvlan-mode: l2
ipam:
driver: default
config:
- subnet: 192.168.0.0/24
gateway: 192.168.0.1
ip_range: 192.168.0.1/24
EOT
select “internal network”
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
cat << EOT sudo tee /etc/netplan/00-installer-config.yaml
network:
ethernets:
enp0s3:
addresses:
- 192.168.0.130/24
dhcp4: no
dhcp6: no
version: 2
EOT
mkdir ~/docker
cd ~/docker
cat << EOT >docker-compose.yml
version: '2'
services:
ros:
container_name: ros2
image: osrf/ros:galactic-desktop
hostname: ros-host
domainname: test
networks:
network:
ipv4_address: 192.168.0.131
command: ros2 run demo_nodes_cpp listener
restart: unless-stopped
networks:
network:
driver: ipvlan
driver_opts:
parent: enp0s3
ipvlan-mode: l2
ipam:
driver: default
config:
- subnet: 192.168.0.0/24
gateway: 192.168.0.1
ip_range: 192.168.0.1/24
EOT
in clone 1 and 2, navigate to ~/docker and type
docker compose up
when done, please ensure you clean up your network interfaces on each guest clone by typing
docker compose down
This example assumes a subnet of 192.168.8.xxx from the router. Go to both guests and select bridged networking. The guests ip addresses themselves can be assigned by the router’s dhcp server in this example.
cat << EOT sudo tee /etc/netplan/00-installer-config.yaml
network:
ethernets:
enp0s3:
# addresses:
# - 192.168.8.10/24
dhcp4: yes
dhcp6: no
version: 2
EOT
cat << EOT >~/docker/docker-compose.yml
version: '2'
services:
ros:
container_name: ros2
image: osrf/ros:galactic-desktop
hostname: ros-host
domainname: test
networks:
network:
ipv4_address: 192.168.8.11
command: ros2 run demo_nodes_cpp talker
restart: unless-stopped
networks:
network:
driver: ipvlan
driver_opts:
parent: enp0s3
ipvlan-mode: l2
ipam:
driver: default
config:
- subnet: 192.168.8.0/24
gateway: 192.168.8.1
ip_range: 192.168.8.1/24
EOT
cat << EOT sudo tee /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
# addresses:
# - 192.168.8.20/24
dhcp4: yes
dhcp6: no
version: 2
EOT
cat << EOT >~/docker/docker-compose.yml
version: '2'
services:
ros:
container_name: ros2
image: osrf/ros:galactic-desktop
hostname: ros-host
domainname: test
networks:
network:
ipv4_address: 192.168.8.21
command: ros2 run demo_nodes_cpp listener
restart: unless-stopped
networks:
network:
driver: ipvlan
driver_opts:
parent: enp0s3
ipvlan-mode: l2
ipam:
driver: default
config:
- subnet: 192.168.8.0/24
gateway: 192.168.8.1
ip_range: 192.168.8.1/24
EOT