我目前正在尝试使用官方GoLang Docker SDK创建一个Docker容器,并尝试将一个卷从我的localhost挂载到docker容器。
vol := map[string]struct{}{"/pathInDocker":{}}
// This was prepared using example at:
//https://docs.docker.com/develop/sdk/examples/#run-a-container
res, err := cli.ContainerCreate(ctx, &container.Config{
Image: testImageName,
Volumes: vol,
Cmd: []string{"ls", "/"},
}, nil, nil, "")
这适用于创建容器并将“/ pathInDocker”添加到docker容器,但是,我无法弄清楚如何为localhost添加挂载点。
我为vol变量
尝试了以下可能的值vol := map[string]struct{}{"localPath:/pathInDocker":{}}
vol := map[string]struct{}{"\"localPath\":\"/pathInDocker\"":{}}
对于其中的每一个,生成的docker容器都会尝试将地图密钥挂载为docker中的文件夹而不是localhost的挂载点。
我已经挖掘了文档,而我似乎唯一能找到的关于如何配置卷的唯一一行就是这个:
Volumes map[string]struct{} // List of volumes (mounts) used for the container
所以我的问题是如何配置它以便将本地文件夹安装到卷上?
答案 0 :(得分:3)
如果要使用绑定挂载,则需要在 HostConfig 中提供挂载信息。
<div class="container">
<article>
<div class="prop_img">
<img src="image" height="150px" width="200px">
<div class="location">
<p>Location</p>
</div>
</div>
<div class="prop_desc">
<div class="prop_text">
<h3>Headline</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut l est laborum.</p>
</div>
<div class="prop_button">
<input class="detail_button" type="button" name="Details" value="Details">
</div>
</div>
</article>
</div>
如果要使用卷,首先需要创建具有装载路径的卷,然后需要将此卷名称用作源。