容器可以共享框架吗?

时间:2017-01-10 10:09:26

标签: .net iis docker containers microservices

我知道Docker容器可以共享数据卷,但是它们是否可以共享框架?例如,如果我在IIS上运行两个.NET服务,我可以在它们之间共享框架吗?

1 个答案:

答案 0 :(得分:2)

是的,你可以,你通常做的是

备选方案A:

创建一个busybox图像并复制您的框架,将该位置公开为卷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"]

虽然busyscript.sh看起来像

#!/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

在docker-compose.yml中将此图片作为服务添加为“框架”,然后,在您希望他们使用的服务上添加

volume_from
  - framework:ro

优点:

  • 您可以编译,构建和部署framworks soley
  • 运行此额外容器
  • 或多或少没有运行时开销

缺点:

  • 图像大小的开销(高山,30mb)

备选方案B 您使用其中一个服务作为“框架基础”,假设服务A,这意味着您复制该服务上的框架(其中一个使用它)并再次使用VOLUME /opt/framework将其公开为卷< / p> 在服务B中

,同样地,你装载卷

serviceB:
  volume_from
    - serviceA:ro

临:

  • 没有多余的容器

骗局:

  • 框架需要与serviceA一起部署,无论服务A是否需要更新
    • 您对A有依赖,A是否需要更新,所有其他容器因共享而需要重新创建