Dockerfile
:
FROM alpine:3.18
RUN apk add perl perl-http-daemon
COPY server.pl .
CMD ["perl", "server.pl"]
server.pl
:
use strict;
use warnings;
use HTTP::Daemon;
my $d = HTTP::Daemon->new(LocalPort => 8080) or die;
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
$c->send_response(200, undef, [
'Content-Type' => 'text/html; charset=utf-8',
], "hello world (perl)\n");
}
$c->close;
}
go/Dockerfile
:
FROM alpine:3.18 AS build
COPY server.go .
RUN apk add go && go build server.go
FROM alpine:3.18
COPY --from=build /server .
ENTRYPOINT ["/server"]
go/server.go
:
package main
import (
"fmt"
"net/http"
)
func root(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, "hello world (go)\n")
}
func main() {
http.HandleFunc("/", root)
http.ListenAndServe(":8080", nil)
}
server.pl
:
use strict;
use warnings;
{package MyServer;
use HTTP::Response;
use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);
sub handle_request {
my ($self, $cgi) = @_;
my $resp = HTTP::Response->new(200, undef, undef, 'hello world');
$resp->protocol('HTTP/1.0');
print $resp->as_string;
}
}
MyServer->new(80)->run();