Dockerfile
作者:互联网
目录
Dockerfile
docker commit
[root@localhost ~]# docker run -it --name tt centos
在容器中安装vim-common
[root@598de845a59d yum.repos.d]# dnf -y install vim-common
Last metadata expiration check: 0:01:11 ago on Mon 29 Aug
2022 03:32:38 AM UTC.
Dependencies resolved.
=========================================================
Package Arch Version Repo Size
=========================================================
Installing:
vim-common x86_64 2:8.0.1763-16.el8 appstream 6.3 M
Installing dependencies:
vim-filesystem noarch 2:8.0.1763-16.el8 appstream 49 k
Transaction Summary
=========================================================
Install 2 Packages
Total download size: 6.4 M
Installed size: 27 M
Downloading Packages:
(1/2): vim-filesystem-8. 62 kB/s | 49 kB 00:00
(2/2): vim-common-8.0.17 3.5 MB/s | 6.3 MB 00:01
---------------------------------------------------------
Total 3.5 MB/s | 6.4 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : vim-filesystem-2:8.0.1763-16. 1/2
Installing : vim-common-2:8.0.1763-16.el8. 2/2
Running scriptlet: vim-common-2:8.0.1763-16.el8. 2/2
Verifying : vim-common-2:8.0.1763-16.el8. 1/2
Verifying : vim-filesystem-2:8.0.1763-16. 2/2
Installed:
vim-common-2:8.0.1763-16.el8.x86_64
vim-filesystem-2:8.0.1763-16.el8.noarch
Complete!
退出容器后,使用docker commit将tt容器打包为镜像,新镜像名为centoscy:8
[root@localhost ~]# docker commit tt centos:8
sha256:a9e27727dc00456661c708f1b60de1c215511ece57dcbd928a2
1f5e65cacbf1f
[root@localhost ~]# docker images |grep centos
centos 8 a9e27727dc00 27 seconds ago
556MB
centos latest 5d0da3dc9764 11 months ago
231MB
[root@localhost ~]# docker run -it --name tt2 centos:8
[root@22741ef8ba13 /]# rpm -qa vim-common
vim-common-8.0.1763-16.el8.x86_64
这样一个新的镜像就构建完成了,centos:8镜像是在centos镜像基础之上创建
的,通过查看镜像属性,发现centos:8要比centos镜像大一些。
然而,Docker并不建议用户通过这种方式构建镜像。这是一种手工创建镜
像的方式,容易出错,效率低且可重复性弱。更重要的,使用者并不知道
镜像是如何创建出来的,里面是否有恶意程序。也就是说无法对镜像进行
审计,存在安全隐患
基于本地模板导入
[root@localhost ~]# cat ubuntu-12.04-x86-minimal.tar.gz
|docker import - ubuntu:12.04
sha256:a6bb1e8b5d52e18573ea9bf50c7c7e22f7b873d56d6c1198a0e
68ca16c470c56
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED
SIZE
ubuntu 12.04 a6bb1e8b5d52 9 seconds ago
146MB
centos 8 a9e27727dc00 14 minutes ago
556MB
mysql latest 3218b38490ce 8 months ago
516MB
httpd latest dabbfbe0c57b 8 months ago
144MB
centos latest 5d0da3dc9764 11 months ago
231MB
Dockerfile
[root@localhost yum.repos.d]# ls
Centos-7.repo epel-7.repo
[root@localhost ~]# vim Dockerfile
[root@localhost ~]# ls
anaconda-ks.cfg kodexplorer4.40.zip
Dockerfile saolei.zip
initial-setup-ks.cfg ubuntu-12.04-x86-minimal.tar.gz
[root@localhost ~]# cat Dockerfile
FROM centos:7
MAINTAINER www.dly.com
ADD Centos-7.repo/etc/yum.repo.com
ADD epel-7.repo /etc/yum.repo.d
RUN dnf -y install nginx
EXPOSE 80
CMD [ "/usr/sbin/nginx" ,"-g","daemon off;" ]
[root@localhost ~]# docker build -t nginx:v1 .
Successfully built e5f0f6dc59d1
Successfully tagged nginx:v1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED
SIZE
nginx v1 e5f0f6dc59d1 14 minutes ago
459MB
mysql latest 3218b38490ce 8 months ago
516MB
httpd latest dabbfbe0c57b 8 months ago
144MB
centos 7 eeb6ee3f44bd 11 months ago
204MB
[root@localhost ~]# docker run -dit -p 88:80 nginx:v1
da6f1247f6892077f149babb30f42849149f73bcef5d25ac851c0ee35d
0c627b
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS
NAMES
da6f1247f689 nginx:v1 "/usr/sbin/nginx -g …" 3
seconds ago Up 2 seconds 0.0.0.0:88->80/tcp, :::88-
>80/tcp epic_mendel
[root@localhost ~]# docker exec -it da /bin/bash
[root@da6f1247f689 /]# cd /usr/share/nginx/html/
[root@da6f1247f689 html]# ls
404.html en-US img nginx-logo.png
50x.html icons index.html poweredby.png
[root@da6f1247f689 html]# rm -rf index.html
[root@da6f1247f689 html]# echo dly > index.html
[root@da6f1247f689 html]# ls
404.html en-US img nginx-logo.png
50x.html icons index.html poweredby.png
标签:ago,centos,Dockerfile,vim,html,root,localhost 来源: https://www.cnblogs.com/loronoa/p/16637550.html