太多的码头支架

时间:2016-04-03 08:01:47

标签: docker

我在docker镜像中有一个Web应用程序。 Web应用程序有点复杂,所以每次我在我的应用程序中创建一个新组件时,我必须安装另一个目录。问题是我最终会得到一个具有太多坐载的命令:

docker run -v ... -v ... -v ... ... myimage

对此有更好的解决方案吗?

3 个答案:

答案 0 :(得分:0)

如果问题是命令变得太长而无法在终端中输入,则可以使用docker compose或自定义脚本。然后,您将能够安装所需数量的卷,而无需在启动容器时重写所有内容。

答案 1 :(得分:0)

dockerization的主要思想是你有不可变的容器,你可以在任何地方以相同的结果运行(无状态)。如果您的容器具有状态,则可能是您的应用程序的架构解决方案不良也许你应该将你的申请分开两个。例如,第一个应用程序将是无状态的,另一个将管理您的第一个应用程序存储。作为变体,您只能在一个卷中创建所有新目录:

 -v ./app_state:/app_state

使用下一个app_state目录结构

app_state
|__ subvolume_1
|__ subvolume_2
|
.
.
.
|__ subvolume_n

答案 2 :(得分:0)

好的,所以我想你的Web应用程序在数据库的某个地方存储项目列表以及它存储在文件系统中的路径。如果您可以修改Web应用程序的源,则可以添加一个创建映射项目路径的文件的过程。然后创建一个启动容器的脚本,并将每个项目挂载到该文件中(通过使用awk解析)。如果您无法修改Web应用程序,请确保您至少可以访问数据库中的项目列表,并在您的容器中运行脚本直接进行解析过程

因此您的网络应用会创建一个类似的文件:

-- Pathpiece
instance (KnownSymbol sym, GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (sym :> sa) (sym :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) server
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)

-- Capture
instance (KnownSymbol sym, GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (Capture sym a :> sa) (Capture sym1 a :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server a = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) (server a)
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)

-- QueryParam
instance (KnownSymbol sym, GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (QueryParam sym a :> sa) (QueryParam sym a :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server ma = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) (server ma)
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)

-- QueryParams
instance (KnownSymbol sym, GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (QueryParams sym a :> sa) (QueryParams sym a :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server as = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) (server as)
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)

-- QueryFlag
instance (KnownSymbol sym, GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (QueryFlag sym :> sa) (QueryFlag sym :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server f = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) (server f)
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)


-- Header
instance (KnownSymbol sym, GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (Header sym a :> sa) (Header sym a :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server ma = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) (server ma)
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)


-- ReqBody
instance (GetEndpoint sa endpoint (PickLeftRight endpoint sa)) => GetEndpoint (ReqBody ct a :> sa) (ReqBody ct a :> endpoint) 'True where
  getEndpoint _ pM _ pEndpoint server a = getEndpoint pLeftRight pM (Proxy :: Proxy sa) (Proxy :: Proxy endpoint) (server a)
    where pLeftRight = Proxy :: Proxy (PickLeftRight endpoint sa)


-- Verb
instance GetEndpoint (Verb n s ct a) (Verb n s ct a) 'True where
  getEndpoint _ _ _ _ server = server


-- Raw
instance GetEndpoint Raw Raw 'True where
  getEndpoint _ _ _ _ server = server

你容器的运行脚本看起来像这样:

Project1 /opt/project1
Project2 /opt/project2