Plan is to use a basic (or minimum size) docker image like scratch or alpine to run the client and server programs. Make sure that CMakeLists.txt has the following directives to build a static binary.
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBS OFF)
Check the binary with ldd <binary_name> command to make sure it does not have dependencies on any shared libraries
Client will send multicast messages and expects unicast response from all listeners. There can be zero, one or more than one listener out there in the local network.
To dockerized client executable, use Dockerfile_client:
FROM scratch
WORKDIR /app
ADD ./theClient /app
CMD ["/app/theClient"]
sudo docker build -t the_client -f Dockerfile_client .
The server will join a multicast group and wait for a message. Once it receives a multicast packet, it sends unicast reply to the sender.
To dockerized server executable, use Dockerfile_server:
FROM scratch
WORKDIR /app
ADD ./theServer /app
CMD ["/app/theServer"]
sudo docker build -t the_server -f Dockerfile_server .
Note: Change enp3s0 below to match with your host-machine's interface name
sudo docker network create -d ipvlan \
--subnet=192.168.92.0/24 \
--gateway=192.168.92.1 \
-o ipvlan_mode=l2 \
-o parent=enp3s0 \
my_network
Make sure to assign a unique static IP address within the subnet for each instance and avoid IP address conflicts
sudo docker run -it \
--network my_network \
--ip 192.168.92.100 \
--cap-add NET_ADMIN \
the_server
sudo docker run -it \
--network my_network \
--ip 10.255.30.200 \
--cap-add NET_ADMIN \
the_client
https://www.cs.unc.edu/~jeffay/dirt/FAQ/comp249-001-F99/mcast-socket.html
sudo docker stop $(sudo docker ps -q)
sudo docker rmi -f $sudo docker images -q)