在Apache on Docker容器中运行perl CGI脚本
我已经制作了脚本,并从/usr/lib/cgi-bin在我的虚拟机上运行了它。我需要这个脚本在docker容器中以相同的方式运行。我刚刚使用docker,目前Dockerfile中有以下配置。我不确定我是否将脚本放在正确的目录中,或者我是否以正确的方式执行了此操作。在8080端口上运行容器后,我试图转到在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
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/中,但它们似乎都不起作用