Docker with CGI perl

hello world tutorial

lojorider lojo
Aug 23, 2017 · 1 min read

File Structure

|
compose
| |
| |--- docker-compose
| |--- Dockerfile
| |--- vhost.conf
|
html
|
|--- index.html
|--- hello_world.pl

File Script

  • docker-compose
version: '3'
services:
web:
container_name: web_cgi
build:
context: .

volumes:
- ./../html:/var/www
- ./../log/web:/var/log/nginx/web
ports:
- "8080:80"
  • Dockerfile
FROM nginx:1.10RUN apt-get clean && apt-get update && apt-get install -y nano spawn-fcgi fcgiwrap wget curlRUN sed -i 's/www-data/nginx/g' /etc/init.d/fcgiwrap
RUN chown nginx:nginx /etc/init.d/fcgiwrap
ADD ./vhost.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/wwwCMD /etc/init.d/fcgiwrap start \
&& nginx -g 'daemon off;'
  • vhost.conf
server {

listen 80;
index index.php index.html;
root /var/www;
location ~ \.pl$ {
gzip off;
fastcgi_param SERVER_NAME \$http_host;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

error_log /var/log/nginx/web/error.log;
access_log /var/log/nginx/web/access.log;
}
  • hello_world.pl
#!/usr/bin/perl -wT
print "Content-type: text/plain\n\n";
print "Hello World In CGI Perl"
  • index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Hello World In html file</h1>

</body>
</html>

Run Script

run command

> cd compose> docker-compose up -d --build

Test

  • test index.html
http://ip-host:8080/index.html
  • test hello_world.pl
http://ip-host:8080/hello_world.pl

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade