Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Apache on Docker容器中运行perl CGI脚本_Docker_Apache_Perl_Ubuntu - Fatal编程技术网

在Apache on Docker容器中运行perl CGI脚本

在Apache on Docker容器中运行perl CGI脚本,docker,apache,perl,ubuntu,Docker,Apache,Perl,Ubuntu,我已经制作了脚本,并从/usr/lib/cgi-bin在我的虚拟机上运行了它。我需要这个脚本在docker容器中以相同的方式运行。我刚刚使用docker,目前Dockerfile中有以下配置。我不确定我是否将脚本放在正确的目录中,或者我是否以正确的方式执行了此操作。在8080端口上运行容器后,我试图转到ip\u地址:8080/cgi-bin/shipping.pl,但这只是说明无法访问该站点。我已经尝试将副本更改为COPY--chown=www-data:www-data-shipping.pl

我已经制作了脚本,并从/usr/lib/cgi-bin在我的虚拟机上运行了它。我需要这个脚本在docker容器中以相同的方式运行。我刚刚使用docker,目前Dockerfile中有以下配置。我不确定我是否将脚本放在正确的目录中,或者我是否以正确的方式执行了此操作。在8080端口上运行容器后,我试图转到
ip\u地址:8080/cgi-bin/shipping.pl
,但这只是说明无法访问该站点。我已经尝试将副本更改为
COPY--chown=www-data:www-data-shipping.pl.
,以查看是否未授予Apache权限,但这似乎不起作用。非常感谢您的帮助

Dockerfile

FROM ubuntu
RUN apt-get update
RUN DEBIAN_FRONTEND="noninteractive" apt-get install --yes apache2
RUN apt-get install --yes perl
RUN perl -MCPAN -e "install DBI"
RUN perl -MCPAN -e "install DBD::Pg"
RUN a2enmod cgid
RUN service apache2 restart
WORKDIR /usr/lib/cgi-bin
COPY shipping.pl . 
Perl脚本:shipping.pl

#!/usr/bin/perl

# load module
use DBI;

# connect
my $dbh = DBI->connect("DBI:Pg:dbname=shipping;host=192.168.56.3", "postgres", "somepassword", {'RaiseError' => 1});

# execute SELECT query
my $sth = $dbh->prepare("SELECT surname FROM surnames");
$sth->execute();

# iterate through resultset
# print values
while(my $ref = $sth->fetchrow_hashref()) {
    print "Content-type: text/html\n\n";
    print "$ref->{'surname'}";
}

# clean up
$dbh->disconnect();

另请参见如果无法访问该站点,这不是Perl问题。你可以访问站点的任何部分,包括静态页面吗?我还没有尝试过静态页面,但我会尽快尝试,因为我刚刚尝试过,而且apache似乎无法正常工作。我将一个html页面复制到/usr/local/apache2/htdocs/和/var/www/html/中,但它们似乎都不起作用