容器可以共享一个框架吗? [英] Can containers share a framework?

查看:191
本文介绍了容器可以共享一个框架吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

是的,你通常会做的是



strong>替代方案A:



创建一个busybox图像并复制您的框架,将该位置公开为 VOLUME / opt / framework /

 从高山
COPY框架/ opt /框架
VOLUME / opt / framework
COPY busyscript.sh / usr / local / bin / busyscript
运行chmod + x / usr / local / bin / busyscript
CMD [busyscript]

虽然 busyscript.sh 看起来像

 #!/ bin / sh 
#set -x

pid = 0

#SIGTERM-handler
term_handler(){
if [$ pid -ne 0];然后
kill -SIGTERM$ pid
等待$ pid
fi
exit 143; #128 + 15 - SIGTERM
}

#设置处理程序
#在回调时,杀死最后一个后台进程,这是`tail -f / dev / null`并执行指定的处理程序
trap'kill $ {!}; term_handler'SIGTERM

echo开始的代码
#wait forever
while true
do
tail -f / dev / null&等待$ {!}
done

将此图像作为服务在您的docker-compose中添加.yml,让我们说框架,然后,在你想要消费的服务上,你添加

  volume_from 
- 框架:ro

优点:




  • 您可以编译,构建和部署framworks soley

  • 运行这个额外的容器有或多或少的运行时开销



Con:




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


替代B
您将您的一个服务用作框架基础,让我们说服务A,这意味着你复制该服务的框架(其中一个消耗它),并再次使用 VOLUME / opt / framework 将其公开为卷



在服务B中,同样的方式,您挂载卷

  serviceB: 
volume_from
- se rviceA:ro

Pro:




  • 没有额外的容器



Con:




  • 框架需要与serviceA一起部署,无论服务A需要更新


    • 您对A有依赖性,A需要一个更新,所有其他容器需要重新创建由于共享



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 share the framework between them?

解决方案

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:

  • you can compile, build and deploy the framworks soley
  • there is more or less no runtime overhead for running this extra container

Con:

  • image-size overhead ( alpine, 30mb)

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:

  • no extra container

Con:

  • framework needs to be deployed with serviceA, no matter service A would need updates
    • you have a dependency on A, does A need an update, all other containers need to be recreated due to the share

这篇关于容器可以共享一个框架吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆