ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Dockerfile

2022-08-29 22:04:36  阅读:213  来源: 互联网

标签:ago centos Dockerfile vim html root localhost


目录

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有