为什么我的卷有时不会被挂载在我的Docker容器中? [英] Why do my volumes sometime not get mounted in my Docker container when using 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 是关闭,有相关的公开问题:
- 问题#622 :由于docker 1.3.0 / fig 1.0.0卷没有挂载现有的容器
- 问题#723 :docker 1.4的文件卷已损坏。 0
- 问题#443 :本地目录定期无法挂载。
- 拉请求#711 :修复重新创建#711上的卷
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:
- Issue #622: Since docker 1.3.0 / fig 1.0.0 volumes are not mounted when fig up'ing existing containers
- Issue #723: File volumes are broken for docker 1.4.0
- Issue #443: Local directories periodically fail to be mounted.
- Pull Request #711: Fix volumes on recreate #711
这篇关于为什么我的卷有时不会被挂载在我的Docker容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!