Docker Perl应用程序示例
在这个例子中,将演示如何创建一个Perl应用程序并使用Docker执行,此示例包括以下步骤。
1.创建一个目录用来组织应用程序文件
zyiz@ubuntu:~$ mkdir -p /home/zyiz/docker/perl-docker-app
2.更改进入工作目录
zyiz@ubuntu:~$ cd /home/zyiz/docker/perl-docker-app
3.创建一个 Dockerfile 文件
FROM perl:5.20 COPY . /var/www/php WORKDIR /var/www/php CMD [ "perl", "index.pl"]
4.创建一个Perl文件: index.pl
print "Hello from perl file\n";
5.创建Docker映像
现在,创建这个Scala应用程序的Docker映像。 以下命令用于创建Docker映像。
zyiz@ubuntu:~/docker/perl-docker-app$ docker build -t perl-app .
执行上面命令,输出以下结果 -
zyiz@ubuntu:~/docker/perl-docker-app$ sudo docker build -t perl-app . [sudo] password for zyiz: Sorry, try again. [sudo] password for zyiz: Sending build context to Docker daemon 3.072kB Step 1/4 : FROM perl:5.20 5.20: Pulling from library/perl 8b87079b7a06: Pull complete a3ed95caeb02: Pull complete 1bb8eaf3d643: Pull complete 3e04171ce2e5: Pull complete 0b73d3fea769: Pull complete ffb34b57cdf2: Pull complete 8eeaf71aee14: Pull complete 72cfc9cbff48: Pull complete 2d693787a8c5: Pull complete Digest: sha256:5e06bbcf01ed88d6812839bcc7645a3960361a6843e14b6337de2897dfb2863f Status: Downloaded newer image for perl:5.20 ---> bbe5a82c1dbe Step 2/4 : COPY . /var/www/php ---> 4b03e9f6baca Removing intermediate container 822fd298a2bd Step 3/4 : WORKDIR /var/www/php ---> afe356a8d214 Removing intermediate container 920751b0eef1 Step 4/4 : CMD perl index.pl ---> Running in a5f1b352be9f ---> 774aa9644b86 Removing intermediate container a5f1b352be9f Successfully built 774aa9644b86 Successfully tagged perl-app:latest zyiz@ubuntu:~/docker/perl-docker-app$
6.运行Scala Docker映像
zyiz@ubuntu:~/docker/perl-docker-app$ sudo docker run perl-app
运行docker映像后,执行perl脚本,并在控制台屏幕中打印一条消息,如下所示 -
zyiz@ubuntu:~/docker/perl-docker-app$ sudo docker run perl-app Hello from perl file zyiz@ubuntu:~/docker/perl-docker-app$
关注微信小程序
扫描二维码
程序员编程王