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

时间:2015-12-09 23:52:31

标签: docker

尝试使用" 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

3 个答案:

答案 0 :(得分:23)

这类似于@ 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/我仍然有“错误的文件描述符”日志输出。

答案 1 :(得分:16)

此问题的快速解决方法是使用较旧版本的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上添加了写入依赖项。如果您要将此策略转换为另一个示例,那么理解此分析非常重要。

答案 2 :(得分:0)

回答上面的评论 - 不,它没有解决问题,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 host是win7x64主机上的vmware ubuntu 14.04x64 DT