I\'m aware that Docker containers can share a data volume but is it possible for them to share frameworks? For instance, if i have two .NET services running on IIS can I just sh
Yes you can, what you usually do is
Alternative A:
create a busybox image and COPY your framework, expose the location as a volume VOLUME /opt/framework/
FROM alpine
COPY framework /opt/framework
VOLUME /opt/framework
COPY busyscript.sh /usr/local/bin/busyscript
RUN chmod +x /usr/local/bin/busyscript
CMD ["busyscript"]
While the busyscript.sh
looks like
#!/bin/sh
#set -x
pid=0
# SIGTERM-handler
term_handler() {
if [ $pid -ne 0 ]; then
kill -SIGTERM "$pid"
wait "$pid"
fi
exit 143; # 128 + 15 -- SIGTERM
}
# setup handlers
# on callback, kill the last background process, which is `tail -f /dev/null` and execute the specified handler
trap 'kill ${!}; term_handler' SIGTERM
echo "Started code"
# wait forever
while true
do
tail -f /dev/null & wait ${!}
done
Add this image as a service in your docker-compose.yml as lets say "framework", then, on the services you want them to consume, you add
volume_from
- framework:ro
Pros:
Con:
Alternative B
You use one of your services as the "framework base", lets say service A, that means you copy the framework on that service ( one of the 2 consuming it ) and also again use VOLUME /opt/framework
to expose it as volume
in the service B, the same way, you mount the volume
serviceB:
volume_from
- serviceA:ro
Pro:
Con: