【问题标题】:Can I populate the content of the Volume I created in Bluemix Containers?我可以填充我在 Bluemix Containers 中创建的卷的内容吗?
【发布时间】:2015-09-16 13:20:52
【问题描述】:
我在我的 Bluemix Container 注册表中上传了一个 Oracle11g 数据库映像。
我使用 CLI 在 IBM Containers 中创建了一个名为 oradbdata 的卷:
cf ic volume create oradbdata
现在我需要在运行容器之前将一些内容复制到这个卷中。
是否可以访问此卷并填充其内容?
莱昂内尔
【问题讨论】:
标签:
docker
containers
ibm-cloud
【解决方案1】:
当您启动容器时,您可以将卷关联到所需的容器路径;例如:卷 oradbdata -> /var/lib/oradata。当容器随后启动时,/var/lib/oradata 将映射到您的卷,此时,您可以在容器启动时将数据放入其中,也可以通过 ssh 访问容器。
【解决方案2】:
我建议在容器构建期间将您的文件添加到容器中(例如,添加到 /src 目录中)。然后为您的应用程序使用启动脚本。在脚本中,您将检查挂载的目录是否包含您需要的文件。如果没有,则将内容复制过来。像这样的:
#!/bin/bash
# Test if the volume is empty
if [ ! -f /mountpoint/testfile ]; then
# Copy the contents from the container image into the volume
cp -R /src/* /mountpoint
fi
# Now start the app here
/usr/bin/myapp