[4] Użycie „Dockerfile”
24 lipca 2020Użyjemy teraz Dockerfile i stworzymy obraz kontenera automatycznie.
Jest możliwe również użycie go jako menadżera kontenerów oraz ich konfiguracji.
[1] Użyjemy teraz Dockerfile, aby stworzyć kontener z zainstalowanym Nginx’em i uruchomimy go.
[root@lsr01vm ~]# mcedit Dockerfile # tworzymy nowy plik FROM centos MAINTAINER ZicherLab <admin@zicher.lab> RUN dnf -y install nginx RUN echo "Test DOCKERFILE w NGINX'ie" > /usr/share/nginx/html/index.html EXPOSE 80 CMD ["/usr/sbin/nginx", "-g", "daemon off;"] # budujemy nowy obraz => docker build -t [NazwaObrazu]:[Tag] . [root@lsr01vm ~]# podman build -t zicher.lab/nginx_server:latest . STEP 1: FROM centos STEP 2: MAINTAINER ZicherLab <admin@zicher.lab> cc858bddecedb13917fd78293fb1137ee213ffe06e24450773c683f68ab51db7 STEP 3: RUN dnf -y install nginx CentOS-8 - AppStream 2.3 MB/s | 5.8 MB 00:02 CentOS-8 - Base 1.5 MB/s | 2.2 MB 00:01 CentOS-8 - Extras 9.3 kB/s | 7.0 kB 00:00 Dependencies resolved. ============================================================================================== Package Arch Version Repo Size ============================================================================================== Installing: nginx x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 570 k Installing dependencies: dejavu-fonts-common noarch 2.35-6.el8 BaseOS 74 k dejavu-sans-fonts noarch 2.35-6.el8 BaseOS 1.5 M fontconfig x86_64 2.13.1-3.el8 BaseOS 275 k fontpackages-filesystem noarch 1.44-22.el8 BaseOS 16 k freetype x86_64 2.9.1-4.el8 BaseOS 393 k gd x86_64 2.2.5-6.el8 AppStream 144 k jbigkit-libs x86_64 2.1-14.el8 AppStream 55 k libX11 x86_64 1.6.8-3.el8 AppStream 611 k libX11-common noarch 1.6.8-3.el8 AppStream 158 k libXau x86_64 1.0.8-13.el8 AppStream 36 k libXpm x86_64 3.5.12-8.el8 AppStream 58 k libjpeg-turbo x86_64 1.5.3-10.el8 AppStream 156 k libpng x86_64 2:1.6.34-5.el8 BaseOS 126 k libtiff x86_64 4.0.9-17.el8 AppStream 188 k libwebp x86_64 1.0.0-1.el8 AppStream 273 k libxcb x86_64 1.13.1-1.el8 AppStream 229 k libxslt x86_64 1.1.32-4.el8 BaseOS 249 k nginx-all-modules noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 23 k nginx-filesystem noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 24 k nginx-mod-http-image-filter x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 35 k nginx-mod-http-perl x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 45 k nginx-mod-http-xslt-filter x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 33 k nginx-mod-mail x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 64 k nginx-mod-stream x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 85 k openssl x86_64 1:1.1.1c-15.el8 BaseOS 697 k perl-Carp noarch 1.42-396.el8 BaseOS 30 k perl-Errno x86_64 1.28-416.el8 BaseOS 76 k perl-Exporter noarch 5.72-396.el8 BaseOS 34 k perl-File-Path noarch 2.15-2.el8 BaseOS 38 k perl-IO x86_64 1.38-416.el8 BaseOS 141 k perl-PathTools x86_64 3.74-1.el8 BaseOS 90 k perl-Scalar-List-Utils x86_64 3:1.49-2.el8 BaseOS 68 k perl-Socket x86_64 4:2.027-3.el8 BaseOS 59 k perl-Text-Tabs+Wrap noarch 2013.0523-395.el8 BaseOS 24 k perl-Unicode-Normalize x86_64 1.25-396.el8 BaseOS 82 k perl-constant noarch 1.33-396.el8 BaseOS 25 k perl-interpreter x86_64 4:5.26.3-416.el8 BaseOS 6.3 M perl-libs x86_64 4:5.26.3-416.el8 BaseOS 1.6 M perl-macros x86_64 4:5.26.3-416.el8 BaseOS 72 k perl-parent noarch 1:0.237-1.el8 BaseOS 20 k perl-threads x86_64 1:2.21-2.el8 BaseOS 61 k perl-threads-shared x86_64 1.58-2.el8 BaseOS 48 k Enabling module streams: nginx 1.14 Transaction Summary ============================================================================================== Install 43 Packages Total download size: 15 M Installed size: 38 M Downloading Packages: (1/43): jbigkit-libs-2.1-14.el8.x86_64.rpm 206 kB/s | 55 kB 00:00 TA (2/43): gd-2.2.5-6.el8.x86_64.rpm 423 kB/s | 144 kB 00:00 (3/43): libXau-1.0.8-13.el8.x86_64.rpm 498 kB/s | 36 kB 00:00 (4/43): libX11-common-1.6.8-3.el8.noarch.rpm 987 kB/s | 158 kB 00:00 (5/43): libX11-1.6.8-3.el8.x86_64.rpm 1.3 MB/s | 611 kB 00:00 (6/43): libXpm-3.5.12-8.el8.x86_64.rpm 797 kB/s | 58 kB 00:00 (7/43): libtiff-4.0.9-17.el8.x86_64.rpm 2.2 MB/s | 188 kB 00:00 (8/43): libjpeg-turbo-1.5.3-10.el8.x86_64.rpm 1.3 MB/s | 156 kB 00:00 (9/43): libxcb-1.13.1-1.el8.x86_64.rpm 2.7 MB/s | 229 kB 00:00 (10/43): libwebp-1.0.0-1.el8.x86_64.rpm 1.5 MB/s | 273 kB 00:00 (11/43): nginx-all-modules-1.14.1-9.module_el8. 318 kB/s | 23 kB 00:00 (12/43): nginx-filesystem-1.14.1-9.module_el8.0 361 kB/s | 24 kB 00:00 (13/43): nginx-1.14.1-9.module_el8.0.0+184+e34f 2.4 MB/s | 570 kB 00:00 (14/43): nginx-mod-http-image-filter-1.14.1-9.m 476 kB/s | 35 kB 00:00 (15/43): nginx-mod-http-perl-1.14.1-9.module_el 727 kB/s | 45 kB 00:00 (16/43): nginx-mod-http-xslt-filter-1.14.1-9.mo 655 kB/s | 33 kB 00:00 (17/43): nginx-mod-mail-1.14.1-9.module_el8.0.0 1.2 MB/s | 64 kB 00:00 (18/43): nginx-mod-stream-1.14.1-9.module_el8.0 1.4 MB/s | 85 kB 00:00 (19/43): dejavu-fonts-common-2.35-6.el8.noarch. 337 kB/s | 74 kB 00:00 (20/43): fontpackages-filesystem-1.44-22.el8.no 309 kB/s | 16 kB 00:00 (21/43): fontconfig-2.13.1-3.el8.x86_64.rpm 777 kB/s | 275 kB 00:00 (22/43): libpng-1.6.34-5.el8.x86_64.rpm 932 kB/s | 126 kB 00:00 (23/43): freetype-2.9.1-4.el8.x86_64.rpm 1.1 MB/s | 393 kB 00:00 (24/43): libxslt-1.1.32-4.el8.x86_64.rpm 1.3 MB/s | 249 kB 00:00 (25/43): perl-Carp-1.42-396.el8.noarch.rpm 590 kB/s | 30 kB 00:00 (26/43): perl-Errno-1.28-416.el8.x86_64.rpm 1.2 MB/s | 76 kB 00:00 (27/43): perl-Exporter-5.72-396.el8.noarch.rpm 657 kB/s | 34 kB 00:00 (28/43): perl-File-Path-2.15-2.el8.noarch.rpm 767 kB/s | 38 kB 00:00 (29/43): perl-IO-1.38-416.el8.x86_64.rpm 1.2 MB/s | 141 kB 00:00 (30/43): dejavu-sans-fonts-2.35-6.el8.noarch.rp 1.4 MB/s | 1.5 MB 00:01 (31/43): openssl-1.1.1c-15.el8.x86_64.rpm 1.5 MB/s | 697 kB 00:00 (32/43): perl-PathTools-3.74-1.el8.x86_64.rpm 1.1 MB/s | 90 kB 00:00 (33/43): perl-Scalar-List-Utils-1.49-2.el8.x86_ 1.0 MB/s | 68 kB 00:00 (34/43): perl-Socket-2.027-3.el8.x86_64.rpm 891 kB/s | 59 kB 00:00 (35/43): perl-Text-Tabs+Wrap-2013.0523-395.el8. 549 kB/s | 24 kB 00:00 (36/43): perl-constant-1.33-396.el8.noarch.rpm 453 kB/s | 25 kB 00:00 (37/43): perl-Unicode-Normalize-1.25-396.el8.x8 1.3 MB/s | 82 kB 00:00 (38/43): perl-macros-5.26.3-416.el8.x86_64.rpm 973 kB/s | 72 kB 00:00 (39/43): perl-parent-0.237-1.el8.noarch.rpm 413 kB/s | 20 kB 00:00 (40/43): perl-threads-2.21-2.el8.x86_64.rpm 876 kB/s | 61 kB 00:00 (41/43): perl-threads-shared-1.58-2.el8.x86_64. 698 kB/s | 48 kB 00:00 (42/43): perl-libs-5.26.3-416.el8.x86_64.rpm 2.3 MB/s | 1.6 MB 00:00 (43/43): perl-interpreter-5.26.3-416.el8.x86_64 4.0 MB/s | 6.3 MB 00:01 -------------------------------------------------------------------------------- Total 3.7 MB/s | 15 MB 00:03 warning: /var/cache/dnf/AppStream-02e86d1c976ab532/packages/gd-2.2.5-6.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY CentOS-8 - AppStream 1.6 MB/s | 1.6 kB 00:00 Importing GPG key 0x8483C65D: Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>" Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : perl-Exporter-5.72-396.el8.noarch 1/43 Installing : perl-libs-4:5.26.3-416.el8.x86_64 2/43 Installing : perl-Carp-1.42-396.el8.noarch 3/43 Installing : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 4/43 Installing : libpng-2:1.6.34-5.el8.x86_64 5/43 Installing : freetype-2.9.1-4.el8.x86_64 6/43 Installing : fontpackages-filesystem-1.44-22.el8.noarch 7/43 Installing : libjpeg-turbo-1.5.3-10.el8.x86_64 8/43 Installing : dejavu-fonts-common-2.35-6.el8.noarch 9/43 Installing : dejavu-sans-fonts-2.35-6.el8.noarch 10/43 Installing : fontconfig-2.13.1-3.el8.x86_64 11/43 Running scriptlet: fontconfig-2.13.1-3.el8.x86_64 11/43 Installing : perl-macros-4:5.26.3-416.el8.x86_64 12/43 Installing : perl-parent-1:0.237-1.el8.noarch 13/43 Installing : perl-Errno-1.28-416.el8.x86_64 14/43 Installing : perl-Socket-4:2.027-3.el8.x86_64 15/43 Installing : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch 16/43 Installing : perl-Unicode-Normalize-1.25-396.el8.x86_64 17/43 Installing : perl-File-Path-2.15-2.el8.noarch 18/43 Installing : perl-IO-1.38-416.el8.x86_64 19/43 Installing : perl-PathTools-3.74-1.el8.x86_64 20/43 Installing : perl-constant-1.33-396.el8.noarch 21/43 Installing : perl-threads-1:2.21-2.el8.x86_64 22/43 Installing : perl-threads-shared-1.58-2.el8.x86_64 23/43 Installing : perl-interpreter-4:5.26.3-416.el8.x86_64 24/43 Installing : openssl-1:1.1.1c-15.el8.x86_64 25/43 Installing : libxslt-1.1.32-4.el8.x86_64 26/43 Running scriptlet: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34 27/43 Installing : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34 27/43 Installing : libwebp-1.0.0-1.el8.x86_64 28/43 Installing : libXau-1.0.8-13.el8.x86_64 29/43 Installing : libxcb-1.13.1-1.el8.x86_64 30/43 Installing : libX11-common-1.6.8-3.el8.noarch 31/43 Installing : libX11-1.6.8-3.el8.x86_64 32/43 Installing : libXpm-3.5.12-8.el8.x86_64 33/43 Installing : jbigkit-libs-2.1-14.el8.x86_64 34/43 Running scriptlet: jbigkit-libs-2.1-14.el8.x86_64 34/43 Installing : libtiff-4.0.9-17.el8.x86_64 35/43 Installing : gd-2.2.5-6.el8.x86_64 36/43 Running scriptlet: gd-2.2.5-6.el8.x86_64 36/43 Installing : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+ 37/43 Running scriptlet: nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+ 37/43 Installing : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0 38/43 Running scriptlet: nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0 38/43 Installing : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fe 39/43 Running scriptlet: nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fe 39/43 Installing : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34 40/43 Running scriptlet: nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34 40/43 Installing : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_6 41/43 Running scriptlet: nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_6 41/43 Installing : nginx-mod-http-image-filter-1:1.14.1-9.module_el8. 42/43 Running scriptlet: nginx-mod-http-image-filter-1:1.14.1-9.module_el8. 42/43 Installing : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e3 43/43 Running scriptlet: nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e3 43/43 Running scriptlet: fontconfig-2.13.1-3.el8.x86_64 43/43 Verifying : gd-2.2.5-6.el8.x86_64 1/43 Verifying : jbigkit-libs-2.1-14.el8.x86_64 2/43 Verifying : libX11-1.6.8-3.el8.x86_64 3/43 Verifying : libX11-common-1.6.8-3.el8.noarch 4/43 Verifying : libXau-1.0.8-13.el8.x86_64 5/43 Verifying : libXpm-3.5.12-8.el8.x86_64 6/43 Verifying : libjpeg-turbo-1.5.3-10.el8.x86_64 7/43 Verifying : libtiff-4.0.9-17.el8.x86_64 8/43 Verifying : libwebp-1.0.0-1.el8.x86_64 9/43 Verifying : libxcb-1.13.1-1.el8.x86_64 10/43 Verifying : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_6 11/43 Verifying : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e3 12/43 Verifying : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34 13/43 Verifying : nginx-mod-http-image-filter-1:1.14.1-9.module_el8. 14/43 Verifying : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+ 15/43 Verifying : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0 16/43 Verifying : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fe 17/43 Verifying : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34 18/43 Verifying : dejavu-fonts-common-2.35-6.el8.noarch 19/43 Verifying : dejavu-sans-fonts-2.35-6.el8.noarch 20/43 Verifying : fontconfig-2.13.1-3.el8.x86_64 21/43 Verifying : fontpackages-filesystem-1.44-22.el8.noarch 22/43 Verifying : freetype-2.9.1-4.el8.x86_64 23/43 Verifying : libpng-2:1.6.34-5.el8.x86_64 24/43 Verifying : libxslt-1.1.32-4.el8.x86_64 25/43 Verifying : openssl-1:1.1.1c-15.el8.x86_64 26/43 Verifying : perl-Carp-1.42-396.el8.noarch 27/43 Verifying : perl-Errno-1.28-416.el8.x86_64 28/43 Verifying : perl-Exporter-5.72-396.el8.noarch 29/43 Verifying : perl-File-Path-2.15-2.el8.noarch 30/43 Verifying : perl-IO-1.38-416.el8.x86_64 31/43 Verifying : perl-PathTools-3.74-1.el8.x86_64 32/43 Verifying : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 33/43 Verifying : perl-Socket-4:2.027-3.el8.x86_64 34/43 Verifying : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch 35/43 Verifying : perl-Unicode-Normalize-1.25-396.el8.x86_64 36/43 Verifying : perl-constant-1.33-396.el8.noarch 37/43 Verifying : perl-interpreter-4:5.26.3-416.el8.x86_64 38/43 Verifying : perl-libs-4:5.26.3-416.el8.x86_64 39/43 Verifying : perl-macros-4:5.26.3-416.el8.x86_64 40/43 Verifying : perl-parent-1:0.237-1.el8.noarch 41/43 Verifying : perl-threads-1:2.21-2.el8.x86_64 42/43 Verifying : perl-threads-shared-1.58-2.el8.x86_64 43/43 Installed: dejavu-fonts-common-2.35-6.el8.noarch dejavu-sans-fonts-2.35-6.el8.noarch fontconfig-2.13.1-3.el8.x86_64 fontpackages-filesystem-1.44-22.el8.noarch freetype-2.9.1-4.el8.x86_64 gd-2.2.5-6.el8.x86_64 jbigkit-libs-2.1-14.el8.x86_64 libX11-1.6.8-3.el8.x86_64 libX11-common-1.6.8-3.el8.noarch libXau-1.0.8-13.el8.x86_64 libXpm-3.5.12-8.el8.x86_64 libjpeg-turbo-1.5.3-10.el8.x86_64 libpng-2:1.6.34-5.el8.x86_64 libtiff-4.0.9-17.el8.x86_64 libwebp-1.0.0-1.el8.x86_64 libxcb-1.13.1-1.el8.x86_64 libxslt-1.1.32-4.el8.x86_64 nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 openssl-1:1.1.1c-15.el8.x86_64 perl-Carp-1.42-396.el8.noarch perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-3.el8.x86_64 perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 Complete! 5bf8940321bd22de92862d210eb6ae4422b15a1eab3a89eeea5a79f4c4197107 STEP 4: RUN echo "Test DOCKERFILE w NGINX'ie" > /usr/share/nginx/html/index.html 0ac2890c0750e4d1b514eca2a9ca80cb551942b8b3a95b2b98b2d418a387c298 STEP 5: EXPOSE 80 2d953efc66d02ff6b99f5fd3b3c3feec4228895d086f8d7a368571fb6f3b71a2 STEP 6: CMD ["/usr/sbin/nginx", "-g", "daemon off;"] STEP 7: COMMIT zicher.lab/nginx_server:latest 1ea2f3d4afab8777eeee9dda4bfd2ff8525f14eb3fdb4804a754a32b0612ab79 [root@lsr01vm ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE zicher.lab/nginx_server latest 1ea2f3d4afab 40 seconds ago 299 MB zicher.lab/centos_httpd latest 20386223ebaa 34 minutes ago 270 MB docker.io/library/centos latest 831691599b88 5 weeks ago 223 MB # uruchamiamy kontener [root@lsr01vm ~]# podman run -d -p 80:80 zicher.lab/nginx_server 9c85c933377e1d997d10e9b59317a729ce6e17929f73558fa48cd077ced0bce1 [root@lsr01vm ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9c85c933377e zicher.lab/nginx_server:latest /usr/sbin/nginx -... 18 seconds ago Up 17 seconds ago 0.0.0.0:80->80/tcp competent_chatterjee 0385b11630c6 zicher.lab/centos_httpd:latest /usr/sbin/apachec... 27 minutes ago Up 27 minutes ago 0.0.0.0:8081->80/tcp fervent_edison # sprawdzamy czy działa [root@lsr01vm ~]# curl localhost Test DOCKERFILE w NGINX'ie # dostęp przez sieć kontenera [root@lsr01vm ~]# podman inspect -l | grep \"IPAddress "IPAddress": "10.88.0.5", [root@lsr01vm ~]# curl 10.88.0.5 Test DOCKERFILE w NGINX'ie