I have already made the script and ran it on my VM from /usr/lib/cgi-bin. I need this script to be running the same way in a docker container. I am fairly new to using docker and currently have the below config in my Dockerfile. I'm not sure if i am putting the script in the right directory or not or if I'm even doing this the right way. After running the container on port 8080 I tried to go to ip_adress:8080/cgi-bin/shipping.pl but this just says that the site can't be reached. I have already tried changing the COPY to COPY --chown=www-data:www-data shipping.pl . to see if maybe permission weren't given to Apache, but this didn't seem to work. Any help is greatly appreciated.
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 script: 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();