试试"Docker in Action"一书中的一个例子.
$docker run -d --name wp2 --link wpdb:mysql -p 80 --read-only wordpress:4
......应该已经触发了这个错误......
Read-only file system: AH00023: Couldn't create the rewrite-map mutex (file /var/lock/apache2/rewrite-map.1)”
但事实并非如此.它触发了文件描述符错误......
$docker logs wp2 WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html Wed Dec 9 23:15:21 2015 (21): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:21 2015 (30): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:21 2015 (39): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:21 2015 (48): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (62): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (76): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (90): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (104): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (118): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (132): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (146): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (160): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:15:22 2015 (164): Fatal Error Unable to create lock file: Bad file descriptor (9)
这本书建议我们可以使用这样的卷来完成这项工作......
$docker run -d --name wp3 --link wpdb:mysql -p 80 -v /var/lock/apache2/ -v /var/run/apache2/ --read-only wordpress:4 305e62e18d926a54ac7d1a0fb775f61efdb61486d9d9245933c3b18055bd9856
容器"似乎"开始正常,
但它没有......
$docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6bd4d90f594b mysql:5 "/entrypoint.sh mysql" 21 minutes ago Up 21 minutes 3306/tcp wpdb
日志说这个......
$docker logs wp3 WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html Wed Dec 9 23:31:57 2015 (22): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:57 2015 (31): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:57 2015 (40): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:57 2015 (49): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:57 2015 (63): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (77): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (91): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (105): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (119): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (133): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (147): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (161): Fatal Error Unable to create lock file: Bad file descriptor (9) Wed Dec 9 23:31:58 2015 (165): Fatal Error Unable to create lock file: Bad file descriptor (9)
我不确定为什么会这样.我正在阅读的这本书说这应该有效.我无法找到任何其他人遇到此特定错误的示例.完全删除--read-only标志确实有效.
$docker run -d --name wp3 --link wpdb:mysql -p 80 -v /var/lock/apache2/ -v /var/run/apache2/ wordpress:4 990874c73691c42d3c04aceb19f83a698f90a2f9ddcf1c07fb3cc9b9f1986723 $docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 990874c73691 wordpress:4 "/entrypoint.sh apach" 5 seconds ago Up 4 seconds 0.0.0.0:32773->80/tcp wp3 6bd4d90f594b mysql:5 "/entrypoint.sh mysql" About an hour ago Up About an hour 3306/tcp wpdb
小智.. 26
这类似于@ allingeek的解决方案,但如果没有明确允许访问/ tmp,我无法工作:
docker run -d --name wp --read-only -v /run/lock/apache2/ -v /run/apache2/ -v /tmp/ --link wpdb:mysql -p 80 wordpress:4
没有-v /tmp/
我仍然得到"坏文件描述符"日志输出.
这类似于@ allingeek的解决方案,但如果没有明确允许访问/ tmp,我无法工作:
docker run -d --name wp --read-only -v /run/lock/apache2/ -v /run/apache2/ -v /tmp/ --link wpdb:mysql -p 80 wordpress:4
没有-v /tmp/
我仍然得到"坏文件描述符"日志输出.
此问题的快速解决方法是使用较旧版本的WordPress图像.似乎他们在4.2和4.3之间改变了文件锁定机制.因此,命令变为:
$docker run -d --name wp2 --link wpdb:mysql -p 80 --read-only wordpress:4.2 $docker run -d --name wp3 --link wpdb:mysql -p 80 -v /var/lock/apache2/ -v /var/run/apache2/ --read-only wordpress:4.2
更深入一点,看起来WordPress图像改变了写入这些文件的位置.为了发现差异,我采取了以下步骤:
启动wordpress:4容器,没有只读文件系统
检查文件系统对容器的更改
更改示例以在新位置创建卷
该分析如下:
# Create the writable container $ docker run -d --name wp10 --link wpdb:mysql -p 80 wordpress:4 # Examine the differences $ docker diff wp10 C /run C /run/apache2 A /run/apache2/apache2.pid C /run/lock C /run/lock/apache2 C /tmp # Update the example for the new locations $ docker run -d --name wp15 --read-only -v /run/lock/apache2/ -v /run/apache2/ --link wpdb:mysql -p 80 wordpress:4
如您所见,图像将PID和锁定文件从/ var移动到/ run,并在/ tmp上添加了写入依赖项.如果您要将此策略转换为另一个示例,那么理解此分析非常重要.