为什么我的卷有时不会被挂载在我的Docker容器中? [英] Why do my volumes sometime not get mounted in my Docker container when using fig?

查看:173
本文介绍了为什么我的卷有时不会被挂载在我的Docker容器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Docker / Fig环境中看到一个奇怪的问题。我的假设是由于延迟了容器的容量,但我不知道如何确认。



我有一个容器,具有以下内容: / p>

Dockerfile



  FROM busybox 
MAINTAINER Dan Rumney<电子邮件>

ADD loadsnapshot.sh /loadsnapshot.sh
RUN [chmod,u + x,/loadsnapshot.sh]

VOLUME [ / snapshot]

ENTRYPOINT [/loadsnapshot.sh]



loadnapshot.sh



 #!/ bin / sh 

if [$(ls -A /快照)];然后
echo加载快照...
#做东西
else
echo无快照加载
fi

在我的fig.yml文件中我有:

  pdsvol:
image:busybox
卷:
- / opt / alfresco / alf_data
- / data
- / mysqlbackup
- / ldapbackup
loader:
image:docker.myregistry.com/snapshot.loader:3.5.0
volumes_from:
- pdsvol
卷:
- / opt / snapshots / my-data /:/ snapshot /

这里的目标(可能很明显)是启动数据容器( pdsvol ),然后使用我的机器上运行的一些数据填充它。



我运行这个方法是调用

  fig up pdsvol 

然后

  fig run --rm loader 

我希望看到的是

  builder @ beast:/ opt / docker-vm $ fig run --rm loader 
加载快照...
...东西...
删除dockervm_loader_run_1 ...

,有时候我会做。然而,有时我会看到:

  builder @ beast:/ opt / docker-vm $ fig run --rm loader 
没有要加载的快照
删除dockervm_loader_run_1 ...

我可以运行 fig run -rm loader 一遍又一遍,我会得到两个结果之一。



我的工作理论是有一些延迟的音量有时会发生在 ENTRYPOINT 脚本运行之前,有时候会发生。但是,如果我运行:

  docker run --rm -v / opt / snapshots / my-data /:/ snapshot / busybox ls -A / snapshot 

我始终看到我期待的文件...所以这样反对这个理论。



我知道我可以在 loadsnapshot.sh 中加入骇客,并且看看是否帮助,但我宁愿了解发生了什么,而不是修改一下。



有没有人有任何想法这里发生了什么?



BTW:主机系统是Linux,所以我们在这里使用本地容器。



更新



我尝试将2s延迟放在 loadsnapshot.sh 的顶部,但没有帮助。



更新2



我添加了一些日志记录到fig来转储用于创建容器的配置,在每个实例(fail或no)中都是一样的: / p>

  {
'Env':无,
'主机名':无,
'条目点':无,
'Dns':无,
'内存':0,
'OpenStdin':True,
'用户':无,
' CpuShares':None,
'AttachStdout':True,
'NetworkDisabled':False,
'WorkingDir':None,
'Cmd':None,
' StdinOnce':True,
'AttachStdin':True,
'卷':{u'/ snapshot /':{}},
'MemorySwap':0,
'卷:从
'Tty':True,
'AttachStderr':True,
'Domainname':None,
'Image':'docker.myregistry.com/ snapshot.loader:3.5.0',
'ExposedPorts':无
}


解决方案

我可以使用Docker 1.4.0 / Fig 1.0.1重现问题。



回到 em> Docker 1.3.1 解决了我的问题。



它似乎是一个影响很多人的开放问题。



尽管#443 是关闭,有相关的公开问题:




I'm seeing a strange problem in a Docker/Fig environment. My hypothesis is that it's due to a delay in mounting volumes to containers, but I'm not sure how to confirm that.

I have a container with the following:

Dockerfile

FROM busybox
MAINTAINER Dan Rumney <email>

ADD loadsnapshot.sh /loadsnapshot.sh
RUN ["chmod", "u+x", "/loadsnapshot.sh"]

VOLUME ["/snapshot"]

ENTRYPOINT ["/loadsnapshot.sh"]

loadsnapshot.sh

#!/bin/sh

if [ "$( ls -A /snapshot)" ]; then
  echo "Loading snapshot..."
  # Do stuff
else
  echo "No snapshot to load"
fi

In my fig.yml file I have:

pdsvol:
 image: busybox
 volumes:
 - "/opt/alfresco/alf_data"
 - "/data"
 - "/mysqlbackup"
 - "/ldapbackup"
loader:
 image: "docker.myregistry.com/snapshot.loader:3.5.0"
 volumes_from: 
 - pdsvol
 volumes:
 - "/opt/snapshots/my-data/:/snapshot/"

The goal here (which may be obvious) is to start up a data container (pdsvol) and then populate it with some data that's running on my machine. pdsvol is then shared by a bunch of other containers.

The way I run this is to call

fig up pdsvol

and then

fig run --rm loader

What I expect to see is

builder@beast:/opt/docker-vm$ fig run --rm loader
Loading snapshot...
... stuff ...
Removing dockervm_loader_run_1...

and, sometimes I do. However, sometimes I see:

builder@beast:/opt/docker-vm$ fig run --rm loader
No snapshot to load
Removing dockervm_loader_run_1...

I can run fig run --rm loader over and over and I will get one of the two outcomes.

My working theory was that there was some delay in mounting the volume and sometimes it happens before the ENTRYPOINT script is run and sometimes after. However, if I run:

 docker run --rm -v /opt/snapshots/my-data/:/snapshot/ busybox ls -A /snapshot

I consistently see the files I'm expecting... so this goes against that theory.

I know I could hack at loadsnapshot.sh and put in a delay and see if that helps, but I'd rather understand what's going on than kludge a fix.

Does anyone have any ideas what's going on here?

BTW: the host system is Linux, so we are using native containers here.

Update

I tried putting a 2s delay at the top of loadsnapshot.sh, but it did not help.

Update 2

I added some logging to fig to dump the configuration that is used to create the container and in every instance (fail or no), it's the same:

{
 'Env': None, 
 'Hostname': None, 
 'Entrypoint': None, 
 'Dns': None, 
 'Memory': 0, 
 'OpenStdin': True, 
 'User': None, 
 'CpuShares': None, 
 'AttachStdout': True, 
 'NetworkDisabled': False, 
 'WorkingDir': None, 
 'Cmd': None, 
 'StdinOnce': True, 
 'AttachStdin': True, 
 'Volumes': {u'/snapshot/': {}}, 
 'MemorySwap': 0, 
 'VolumesFrom': None, 
 'Tty': True, 
 'AttachStderr': True, 
 'Domainname': None, 
 'Image': 'docker.myregistry.com/snapshot.loader:3.5.0', 
 'ExposedPorts': None
}

解决方案

I can reproduce the issue with Docker 1.4.0/Fig 1.0.1.

Rolling back to Docker 1.3.1 fixed the issue for me.

It still appears to be an open issue affecting many folks.

Although #443 is closed, there are related open issues:

这篇关于为什么我的卷有时不会被挂载在我的Docker容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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