当前位置: 首页 > news >正文

Dockerfile应用、私有仓库

通过dockerfile创建⼀个在启动容器时,就可以启动httpd服务的镜
步骤
1. 创建⼀个⽬录,⽤于存储Docker file所使⽤的⽂件
1. 在此⽬录中创建Docker file⽂件,以及镜像制作所使⽤的⽂件
1. 使⽤docker build创建镜像
1. 使⽤创建的镜像启动容器(验证)
思考
1. 基础镜像
1. yum -y install httpd
1. 使⽤脚本启动服务(httpd -k start)
1. 应该将httpd服务放在前端执⾏
1. 暴露端⼝ 80/tcp
1. 添加⼀个测试⽂件,⽤于验证软件是否可⽤
过程
# 1.创建⽬录
[root@docker001 ~]# mkdir test
# 2.跳转到⽬录中
[root@docker001 ~]# cd test/
# 3.编辑启动脚本
[root@docker001 test]# vim start.sh
[root@docker001 test]# cat start.sh
######################################
#!/bin/bah
rm -rf /run/httpd/*
exec /sbin/httpd -D FOREGROUND
######################################
# 4.编辑index.html⽂件
[root@docker001 test]# vim index.html
# 5.编辑Dockerfile
[root@docker001 test]# vim Dockerfile
####################################
FROM centos_yum:v0
MAINTAINER "httpd server start
15773141955@163.com"
RUN yum clean all
RUN yum makecache
RUN yum -y install httpd
ADD start.sh /start.sh
RUN chmod -v +x /start.sh
Add index.html /var/www/html/
EXPOSE 80
WORKDIR /
CMD ["/bin/bash","/start.sh"]
####################################
# 6.创建镜像
[root@docker001 test]# docker build -t
centos:httpd .
[+] Building 51.6s (12/12) FINISHED docker:default
=> [internal] load build definition from
Dockerfile 
0.0s
=> => transferring dockerfile: 309B 
0.0s
=> [internal] load metadata for
docker.io/library/centos_yum:v0 
0.0s
=> [internal] load .dockerignore 
0.0s
=> => transferring context: 2B 
0.0s
=> [1/8] FROM docker.io/library/centos_yum:v0 
0.0s
=> [internal] load build context 
0.0s
=> => transferring context: 180B 
0.0s
=> [2/8] RUN YUM clean all 
2.3s
=> [3/8] RUN YUM makecache 
42.7s
=> [4/8] RUN YUM -y install httpd 
5.8s
=> [5/8] ADD START.SH /START.SH 
0.0s
=> [6/8] RUN CHMOD -v +x /start.sh 
0.2s
=> [7/8] ADD INDEX.HTML /VAR/WWW/HTML/ 
0.0s
=> exporting to image 
0.5s
=> => exporting layers 
0.4s
=> => writing image
sha256:a488bc9f4cfb58a91baa57c2ab9faf615d457ff8714
e4e958e7220a253469ed 0.0s
=> => naming to docker.io/library/centos:httpd
# 7.查看镜像[root@docker001 test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos httpd a488bc9f4cfb About a
minute ago 352MB
centos nginx 12fea1b890de 41 hours ago366MB
centos java17 b6bf774de7bb 41 hours ago550MB
centos_yum v0 191d9c84f461 2 days ago 260MB
mysql latest a82a8f162e18 4 weeks ago586MB
# 9.创建容器测试
[root@docker001 test]# docker run -d --name c0
centos:httpd
c245d9f9f3e0d6526d80e117ebd7b4c2870a1e12558192f1da
1e681cabdc4e87
[root@docker001 test]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 
NAMES
c245d9f9f3e0 centos:httpd "/bin/bash
/start.sh" 21 seconds ago Up 20 seconds 
80/tcp c0
# 10.查看ip地址
[root@docker001 test]# docker inspect c0
# 访问测试
[root@docker001 test]# curl 172.17.0.2
p
pp
ppp
pppp
ppppp
pppppp
ppppppp
pppppppp
测试挂载其他项⽬
[root@docker001 test]# docker run -d -v
/opt:/var/www/html --name c1 centos:httpd
3c97af2d11a56b9c2f2ea4eb6bb0a7ff18d6f26d0f777f68a4
eb4a20b9c61835
[root@docker001 test]# eche
"adsfadfafwqrdfqdsafdgdfsgda" > /opt/index.html
-bash: eche: 未找到命令
[root@docker001 test]# echo
"adsfadfafwqrdfqdsafdgdfsgda" > /opt/index.html
[root@docker001 test]# curl 172.17.0.3
adsfadfafwqrdfqdsafdgdfsgda
yum -y install yum-plugin-ovl
练习 配置nginx应⽤镜像
FROM centos:latest
MAINTAINER "NGINX"
RUN rm -rf /etc/yum.repos.d/*
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-vault-
8.5.2111.repo
RUN yum clean all && yum makecache
RUN yum -y install epel-release && yum -y
install nginx
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
WORKDIR /
CMD /usr/sbin/nginx
[root@docker001 ~]# docker run -d --name c1 -
p80:80 -v /opt/:/usr/share/nginx/html/
centos:nginx
948f20e1ed4758e78759de8f9ce9b34a7f44c431bc8ead75b6
70e1a5b488654c
创建私有仓库,在企业中分享项⽬
# 安装仓库镜像
[root@docker001 ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
930bdd4d222e: Pull complete
a15309931e05: Pull complete
6263fb9c821f: Pull complete
86c1d3af3872: Pull complete
a37b1bf6a96f: Pull complete
Digest:
sha256:12120425f07de11a1b899e418d4b0ea174c8d4d572d
45bdb640f93bc7ca06a3d
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
#查看新安装的镜像
[root@docker001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest cfb4d9904335 10 months
ago 25.4MB
centos latest 5d0da3dc9764 2 years ago231MB
# 创建挂载的⽬录
[root@docker001 ~]# mkdir /opt/dockeregistry
# 创建容器,映射端⼝,挂载⽂件
[root@docker001 ~]# docker run -d --name c1 -
p5000:5000 -v
/opt/dockeregistry/:/var/lib/registry
registry:latest
7ec28de22490aee02bd542ef22076f8ba746f7513cf96bf501
d817bc07b38f27
[root@docker001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ec28de22490 registry:latest "/entrypoint.sh
/etc…" 13 seconds ago Up 12 seconds 
0.0.0.0:5000->5000/tcp, :::5000->5000/tcp c1
# 访问⽬录⻚
[root@docker001 ~]# curl
http://10.1.1.50:5000/v2/_catalog
{"repositories":[]}
# 创建仓库
[root@docker001 ~]# vim /etc/docker/daemon.json
[root@docker001 ~]# cat /etc/docker/daemon.json
{"insecure-registries":["http://10.1.1.50:5000" ],"registry-mirrors": ["https://do.nark.eu.org","https://dc.j8.work","https://docker.m.daocloud.io","https://dockerproxy.com","https://docker.mirrors.ustc.edu.cn","https://docker.nju.edu.cn"],"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]}
# 重启docker服务
[root@docker001 ~]# systemctl restart
docker.service
# 查看镜像
[root@docker001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest cfb4d9904335 10 months
ago 25.4MB
centos latest 5d0da3dc9764 2 years ago231MB
# 为要上传的镜像添加标记
[root@docker001 ~]# docker tag centos:latest
10.1.1.50:5000/centos:v0
[root@docker001 ~]# docker images
REPOSITORY TAG IMAGE ID 
CREATED SIZE
registry latest cfb4d9904335 
10 months ago 25.4MB
10.1.1.50:5000/centos v0 5d0da3dc9764 2
years ago 231MB
centos latest 5d0da3dc9764 2
years ago 231MB
10.1.1.50/centos v0 5d0da3dc9764 2
years ago 231MB
[root@docker001 ~]# docker push
10.1.1.50:5000/centos:v0
The push refers to repository
[10.1.1.50:5000/centos]
Get "http://10.1.1.50:5000/v2/": dial tcp
10.1.1.50:5000: connect: connection refused
[root@docker001 ~]# docker start c1
c1
[root@docker001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ec28de22490 registry:latest "/entrypoint.sh
/etc…" 16 minutes ago Up 4 seconds 
0.0.0.0:5000->5000/tcp, :::5000->5000/tcp c1
[root@docker001 ~]# docker push
10.1.1.50:5000/centos:v0
The push refers to repository
[10.1.1.50:5000/centos]
74ddd0ec08fa: Pushed
v0: digest:
sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c8386
3037fa3aab063a7fdb9dc size: 529
[root@docker001 ~]# ls /opt/
1.png assets dist 
index.html
2.png containerd dockeregistry 
nohup.out
application.properties cvloume favicon.ico 
Project_ExamSystem-V1.0.0.war
[root@docker001 ~]# ls /opt/dockeregistry/
docker
[root@docker001 ~]# ls /opt/dockeregistry/docker/
registry
[root@docker001 ~]# ls
/opt/dockeregistry/docker/registry/
v2
[root@docker001 ~]# ls
/opt/dockeregistry/docker/registry/v2/
blobs repositories
[root@docker001 ~]# ls
/opt/dockeregistry/docker/registry/v2/repositories
/
centos
[root@docker001 ~]#
1.拉取registry
docker pull registry
2.创建挂载⽬录
mkdir /regist
3.启动容器,映射端⼝,挂载⽬录
docker run -d --name c0 -v
/regist/:/var/lib/rigistry/ -p5000:5000
registry:latest
4.访问仓库
curl http://192.168.71.50:5000/v2/_catelog
5.配置pull和push,修改daemon.json
vim /etc/docker/daemon.json
{.....,"insecure-registries":["http://192.168.71.50:5000"]
}
:wq
6.修改了配置⽂件,重启docker服务
systemctl restart docker
7.启动registry容器
docker start r1
curl localhost:5000/v2/_catalog

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 昇腾AI处理器的计算核心 - AI Core即DaVinci Core
  • 机器学习数学公式推导之高斯分布
  • 逆向工程核心原理 Chapter22 | 恶意键盘记录器
  • Jenkins安装使用详解,jenkins实现企业级CICD流程
  • 【解压即玩】PC极限竞速:地平线5 顶级豪华中文版 v1.656.386 全DLC 联机补丁810辆全车存档
  • HTML沙漏爱心
  • ansys apdl目标区域节点号提取,通过workbench设置节点集合
  • 安装python软件
  • UniApp 中页面跳转的方法及传值
  • 金融风控领域的15大顶级学术期刊
  • 2024年Java最新面试题总结(三年经验)
  • OSPF理论
  • js数据类型转换-----统一转成字符串String()
  • 22:差分线规则
  • 记录elasticsearch-analysis-dynamic-synonym从8.7.0升级到8.15.0所遇到的问题
  • 【JavaScript】通过闭包创建具有私有属性的实例对象
  • 07.Android之多媒体问题
  • 2018以太坊智能合约编程语言solidity的最佳IDEs
  • Android优雅地处理按钮重复点击
  • Cumulo 的 ClojureScript 模块已经成型
  • es6要点
  • js中forEach回调同异步问题
  • Python 反序列化安全问题(二)
  • python3 使用 asyncio 代替线程
  • -- 查询加强-- 使用如何where子句进行筛选,% _ like的使用
  • 京东美团研发面经
  • 吴恩达Deep Learning课程练习题参考答案——R语言版
  • 一文看透浏览器架构
  • 源码安装memcached和php memcache扩展
  • 最简单的无缝轮播
  • 翻译 | The Principles of OOD 面向对象设计原则
  • 如何用纯 CSS 创作一个货车 loader
  • # Kafka_深入探秘者(2):kafka 生产者
  • # Panda3d 碰撞检测系统介绍
  • #define 用法
  • #我与Java虚拟机的故事#连载05:Java虚拟机的修炼之道
  • #周末课堂# 【Linux + JVM + Mysql高级性能优化班】(火热报名中~~~)
  • (16)UiBot:智能化软件机器人(以头歌抓取课程数据为例)
  • (2024,Vision-LSTM,ViL,xLSTM,ViT,ViM,双向扫描)xLSTM 作为通用视觉骨干
  • (Matalb时序预测)WOA-BP鲸鱼算法优化BP神经网络的多维时序回归预测
  • (NSDate) 时间 (time )比较
  • (SpringBoot)第二章:Spring创建和使用
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (十一)图像的罗伯特梯度锐化
  • (贪心 + 双指针) LeetCode 455. 分发饼干
  • (译) 函数式 JS #1:简介
  • (原创)boost.property_tree解析xml的帮助类以及中文解析问题的解决
  • (转)【Hibernate总结系列】使用举例
  • (转)shell调试方法
  • .jks文件(JAVA KeyStore)
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .NET Core使用NPOI导出复杂,美观的Excel详解
  • .NET MVC之AOP
  • .NetCore部署微服务(二)