docker:致命错误无法创buildlocking文件:错误的文件描述符(9)

尝试从“Docker in Action”书中find一个例子。

$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) 

这本书build议,我们可以使用这样的卷这样的工作…

 $docker run -d --name wp3 --link wpdb:mysql -p 80 -v /var/lock/apache2/ -v /var/run/apache2/ --read-only wordpress:4 305e62e18d926a54ac7d1a0fb775f61efdb61486d9d9245933c3b18055bd9856 

容器“似乎”开始OK
但它没有…

 $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) 

我不知道为什么会发生这种情况。 我正在阅读的书说,这应该工作。 我无法find任何其他人得到这个特定错误的例子。 删除 – 只读标志完全可以工作。

 $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 

这与@ allingeek的解决scheme类似,但是如果不显式地允许访问/ 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/我仍然有“坏文件描述符”日志输出。

这个问题的快速解决scheme是使用旧版本的WordPress图像。 他们似乎改变了4​​.2和4.3之间的文件locking机制。 所以,命令变成:

 $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容器
  • 检查文件系统对容器的更改
  • 更改示例以在新位置创build卷

分析如下:

 # 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和locking文件从/ var移动到/ run,并在/ tmp上添加了写入依赖项。 如果你打算把这个战术转换成另一个例子,理解这个分析是很重要的。

回答上面的评论 – 不,它没有解决这个问题,WP出现并保持。 但未能连接到MySQL。 轮到代理人提前失信退出,我没有足够的声誉来评论以上。

TL;博士

第一次运行,从已知点开始

 docker rm -f $(docker ps -aq) # CAUTION: this removes ALL your containers!!! 

然后运行这个脚本

 #!/bin/bash # CLIENT_ID must be set or need to use script cmdline arg docker-name() { docker inspect --format '{{ .Name }}' "$@" } docker-ip() { docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" } CLIENT_ID=DUKE DB_CID=$(docker run -d -e MYSQL_ROOT_PASSWORD=ch2demo mysql:5) MAILER_CID=$(docker run -d dockerinaction/ch2_mailer) if [ ! -n "$CLIENT_ID" ]; then echo "Client ID not set" exit 1 fi # NOTE: using wordpress:4.2 not latest/4.3 read-only dirs changed WP_CID=$(docker create \ --link $DB_CID:mysql \ --name wp_$CLIENT_ID \ -p 80 \ -v /var/lock/apache2/ \ -v /var/run/apache2/ \ -e WORDPRESS_DB_NAME=$CLIENT_ID \ --read-only wordpress:4.2) docker start $WP_CID AGENT_CID=$(docker create \ --name agent_$CLIENT_ID \ --link $WP_CID:insideweb \ --link $MAILER_CID:insidemailer \ dockerinaction/ch2_agent) docker start $AGENT_CID echo " Client ID: $CLIENT_ID" echo " MySQL ID: $(docker-name $DB_CID) IP: $(docker-ip $DB_CID)" echo " Mailer ID: $(docker-name $MAILER_CID) IP: $(docker-ip $MAILER_CID)" echo " WordPress ID: $(docker-name $WP_CID) IP: $(docker-ip $WP_CID)" echo " Agent ID: $(docker-name $AGENT_CID) IP: $(docker-ip $AGENT_CID)" 

输出:

  Client ID: DUKE MySQL ID: /thirsty_sammet IP: 172.17.0.2 Mailer ID: /sleepy_snyder IP: 172.17.0.3 WordPress ID: /wp_DUKE IP: 172.17.0.4 Agent ID: /agent_DUKE IP: 

 docker ps -a IMAGE COMMAND STATUS PORTS NAMES dockerinaction/ch2_agent "/watcher/watcher.sh" Exited (0) 2 minutes ago agent_DUKE wordpress:4.2 "/entrypoint.sh apach" Up 2 minutes 0.0.0.0:32773->80/tcp wp_DUKE dockerinaction/ch2_mailer "/mailer/mailer.sh" Up 2 minutes 33333/tcp sleepy_snyder mysql:5 "/entrypoint.sh mysql" Up 2 minutes 3306/tcp thirsty_sammet 

所以wordpress出现并保持,但代理失败并退出

 docker logs agent_DUKE nc: can't connect to remote host (172.17.0.4): Connection refused 

WordPress无法连接到MySQL,但不会退出

 docker logs wp_DUKE WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10 MySQL Connection Error: (2002) Connection refused Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10 MySQL Connection Error: (2002) Connection refused Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10 MySQL Connection Error: (2002) Connection refused AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.4. Set the 'ServerName' directive globally to suppress this message [Sun Jan 03 23:37:38.773659 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.12 configured -- resuming normal operations [Sun Jan 03 23:37:38.773802 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 

运行:docker主机是vmware ubuntu 14.04×64 DT在win7x64主机上