Docker Perl應用程序示例
在這個例子中,將演示如何創建一個Perl應用程序並使用Docker執行,此示例包括以下步驟。
1.創建一個目錄用來組織應用程序文件
yiibai@ubuntu:~$ mkdir -p /home/yiibai/docker/perl-docker-app
2.更改進入工作目錄
yiibai@ubuntu:~$ cd /home/yiibai/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映像。
yiibai@ubuntu:~/docker/perl-docker-app$ docker build -t perl-app .
執行上面命令,輸出以下結果 -
yiibai@ubuntu:~/docker/perl-docker-app$ sudo docker build -t perl-app .
[sudo] password for yiibai:
Sorry, try again.
[sudo] password for yiibai:
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
yiibai@ubuntu:~/docker/perl-docker-app$
6.運行Scala Docker映像
yiibai@ubuntu:~/docker/perl-docker-app$ sudo docker run perl-app
運行docker映像後,執行perl腳本,並在控制檯屏幕中打印一條消息,如下所示 -
yiibai@ubuntu:~/docker/perl-docker-app$ sudo docker run perl-app
Hello from perl file
yiibai@ubuntu:~/docker/perl-docker-app$