首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问Docker容器内的cgi脚本时出错,不允许操作:无法绑定unix域套接字

访问Docker容器内的cgi脚本时出错,不允许操作:无法绑定unix域套接字
EN

Stack Overflow用户
提问于 2015-04-03 07:28:06
回答 1查看 2.3K关注 0票数 3

我正在使用Apache::Test来测试我正在编写的Apache处理程序。我的构建环境是一个Docker容器,从这个Dockerfile创建:

代码语言:javascript
复制
FROM    google/debian:wheezy
RUN     apt-get -y install make gcc build-essential
RUN     apt-get -y install sudo
RUN     apt-get -y install apache2-threaded-dev
RUN     apt-get -y install libapache2-mod-perl2 libgd-gd2-perl libgd-tools
RUN     apt-get -y install libtest-harness-perl
RUN     apt-get -y install libtap-formatter-junit-perl libjson-perl

我构建容器并通过以下方式运行它:

代码语言:javascript
复制
docker run -i -t --rm -v $PWD:/opt/51d device-detection:latest /opt/51d/entry.sh

test不允许httpd服务器以根用户身份启动,而我的容器是以根用户身份运行的,因此entry.sh脚本通过执行以下操作为测试创建一个用户:

代码语言:javascript
复制
#!/bin/bash
adduser --disabled-password --gecos '' r
adduser r sudo
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
su -m r -c /opt/51d/build

构建看起来像这样:

代码语言:javascript
复制
perl Makefile.PL && make && make test && sudo make install

代码语言:javascript
复制
t/TEST -start-httpd

我可以通过以下命令很好地访问index.html页面:

代码语言:javascript
复制
wget http://localhost:8529/index.html

但是,当我尝试访问CGI脚本时,我得到:

代码语言:javascript
复制
[Thu Apr 02 23:12:11 2015] [error] (1)Operation not permitted: Couldn't bind unix domain socket /opt/51d/CDK-51DegreesFilter/t/logs/cgisock.267
[Thu Apr 02 23:12:11 2015] [notice] Apache/2.2.22 (Debian) mod_perl/2.0.7 Perl/v5.14.2 configured -- resuming normal operations
[Thu Apr 02 23:12:11 2015] [info] Server built: Dec 23 2014 22:48:32
[Thu Apr 02 23:12:11 2015] [debug] worker.c(1757): AcceptMutex: sysvsem (default: sysvsem)
[Thu Apr 02 23:12:11 2015] [crit] cgid daemon failed to initialize
[Thu Apr 02 23:12:30 2015] [error] [client 127.0.0.1] (2)No such file or directory: unable to connect to cgi daemon after multiple tries: /opt/51d/CDK-51DegreesFilter/t/cgi-bin/index.cgi

/opt/51d/CDK-51DegreesFilter/t/logs/目录是完全打开的:

代码语言:javascript
复制
ls -ld t/logs/
drwxrwxrwx 1 r staff 136 Apr  2 23:24 t/logs/

=====

代码语言:javascript
复制
<IfModule mod_cgid.c>
    ScriptSock /tmp/cgisock
</IfModule>

新的错误消息是:

代码语言:javascript
复制
[Sat Apr 04 04:04:23 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sat Apr 04 04:04:23 2015] [notice] Apache/2.2.22 (Debian) mod_perl/2.0.7 Perl/v5.14.2 configured -- resuming normal operations
[Sat Apr 04 04:04:23 2015] [info] Server built: Dec 23 2014 22:48:32
[Sat Apr 04 04:04:23 2015] [debug] worker.c(1757): AcceptMutex: sysvsem (default: sysvsem)
[Sat Apr 04 04:04:49 2015] [error] (2)No such file or directory: exec of '/opt/51d/CDK-51DegreesFilter/t/cgi-bin/index.cgi' failed
[Sat Apr 04 04:04:49 2015] [error] [client 127.0.0.1] Premature end of script headers: index.cgi
[Sat Apr 04 04:06:14 2015] [error] (2)No such file or directory: exec of '/opt/51d/CDK-51DegreesFilter/t/cgi-bin/index.cgi' failed
[Sat Apr 04 04:06:14 2015] [error] [client 127.0.0.1] Premature end of script headers: index.cgi

=====

由于perl二进制文件的位置不同,修复了exec错误。更新后,一切都很好。

代码语言:javascript
复制
t/TEST
[warning] setting ulimit to allow core files ulimit -c unlimited; /usr/bin/perl /opt/51d/CDK-51DegreesFilter/t/TEST
/usr/sbin/apache2  -d /opt/51d/CDK-51DegreesFilter/t -f /opt/51d/CDK-51DegreesFilter/t/conf/httpd.conf -D APACHE2 -D PERL_USEITHREADS
using Apache/2.2.22 (worker MPM)

waiting 60 seconds for server to start: ..
waiting 60 seconds for server to start: ok (waited 1 secs) 
server localhost:8529 started
t/CDK-51DegreesFilter.t .. ok
All tests successful.
Files=1, Tests=6,  0 wallclock secs ( 0.02 usr  0.02 sys +  0.34 cusr  0.08 csys =  0.46 CPU)
Result: PASS
[warning] server localhost:8529 shutdown
[warning] port 8529 still in use...
done
EN

回答 1

Stack Overflow用户

发布于 2016-12-09 04:37:52

我今天也遇到了类似的问题..使用有效的脚本解决了我的问题..

代码语言:javascript
复制
<IfModule cgid_module>
      #
      # ScriptSock: On threaded servers, designate the path to the UNIX
      # socket used to communicate with the CGI daemon of mod_cgid.
      #
      Scriptsock /usr/local/apache2/cgisock
  </IfModule>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29424132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档