基于Dockerfile构建镜像应用

基于Dockerfile构建镜像应用

image

https://hub.docker.com/_/centos
https://hub.docker.com/_/centos/tags
https://blog.51cto.com/u_16175492/6932082

docker pull centos:centos7
docker build -t httpd:new .
docker build -t httpd:v1 .

[root@localhost sshd]# vim Dockerfile
#基于的基础镜像
FROM spack/centos7
 
#镜像作者信息
MAINTAINER cw <cw@163.com>
 
#镜像执行的命令
RUN yum -y install perl-ExtUtils-Embed perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-Time-HiRes perl-DBI perl-DBD-MySQL
RUN yum -y install httpd
RUN echo "cw-linux" >/var/www/html/index.html
COPY mysqlsla /app
WORKDIR /app

#定义时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 
#开启 22 端口
EXPOSE 80
 
#启动容器时执行指令
CMD ["httpd","-DFOREGROUND"]


基于Dockerfile构建镜像应用1

#基础镜像
FROM centos:7
 
#维护该镜像的用户信息
MAINTAINER Crushlinux <crushlinux@163.com> 
 
#配置Nginx 的YUM 源
RUN rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 
 
#安装nginx
RUN yum -y install nginx
 
#安装mysql 和php
RUN rpm --rebuilddb && yum -y install mariadb-devel mariadb-server mariadb php php-fpm
 
#修改nginx 配置文件,使之支持PHP
ADD default.conf /etc/nginx/conf.d/default.conf
 
#修改php-fpm 配置文件允许nginx 访问
RUN sed -i '/^user/s/apache/nginx/g' /etc/php-fpm.d/www.conf
RUN sed -i '/^group/s/apache/nginx/g' /etc/php-fpm.d/www.conf
 
#设置环境变量,便于管理
ENV MARIADB_USER root
ENV MARIADB_PASS 123456
 
#mysql 数据库授权
ADD db_init.sh /root/db_init.sh
RUN chmod 775 /root/db_init.sh
RUN /root/db_init.sh
 
#添加测试页面
ADD index.php /usr/share/nginx/html/index.php
 
#定义时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 
#分别开启80 端口,443 端口,9000 端口,3360 端口
EXPOSE 80
EXPOSE 9000
EXPOSE 3306
 
#复制脚本,设置权限,启动容器时启动该脚本
ADD run.sh /run.sh
RUN chmod 775 /run.sh
CMD ["/run.sh"]

基于Dockerfile构建镜像应用2



基于Dockerfile构建镜像应用3



yum 配置镜像源 centos7

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

国内知名的yum源镜像站有:

 阿里云,网址:https://opsx.alibaba.com/mirr

 清华大学,网址:http://mirrors.tuna.tsinghua.edu.cn/

 中科大,网址:http://mirrors.ustc.edu.cn/
 
[root@66c8dfbb16e0 yum.repos.d]# cat CentOS-Base2.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7


这是一个CentOS的yum源配置文件。yum源是用于安装和更新软件包的服务器地址。在这个配置文件中,有几个yum源:

[base]:CentOS的基本软件仓库,提供了操作系统的核心组件和基本功能。配置了多个镜像源地址,包括mirrors.aliyun.com、mirrors.aliyuncs.com和mirrors.cloud.aliyuncs.com。gpgcheck设置为1表示进行GPG签名校验,gpgkey指定了GPG密钥的地址。

[updates]:CentOS的更新软件仓库,提供了操作系统的更新补丁和安全修复。配置了多个镜像源地址,同样进行了GPG签名校验。

[extras]:CentOS的额外软件仓库,提供了一些额外的软件包。配置了多个镜像源地址,同样进行了GPG签名校验。

[centosplus]:CentOS的扩展软件仓库,提供了一些扩展功能的软件包。enabled设置为0表示禁用该仓库,不进行安装和更新。

[contrib]:CentOS的贡献软件仓库,提供了一些由CentOS用户贡献的软件包。

通过配置这些yum源,可以方便地安装和更新CentOS操作系统及相关软件包。

https://blog.csdn.net/weixin_44505291/article/details/114269463

yum 配置镜像源 centos8.5

cd /etc/yum.repos.d/    # 进入到配置文件
vi aliyun.repo          # 没有vim命令,只有vi
cat aliyun.repo         # 将一下代码写进aliyun.repo里面
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/
enabled=1
gpgcheck=0

[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/8.5.2111/BaseOS/x86_64/os/
enabled=1
gpgcheck=0

yum clean all && yum makecache fast  # 删除原有的数据缓存并重新建立数据缓存
yum repolist       # 查看yum源仓库是否建立


这是一个CentOS 8.5.2111版本的yum源配置文件。yum源是用于安装和更新软件包的服务器地址。在这个配置文件中,有两个yum源:AppStream和BaseOS。

AppStream是CentOS的一个软件仓库,提供了各种应用程序、工具和库。它的baseurl指定了该仓库的服务器地址,这里使用的是阿里云的镜像源。enabled设置为1表示启用该仓库,gpgcheck设置为0表示不进行GPG签名校验。

BaseOS是CentOS的另一个软件仓库,提供了操作系统的基本组件和核心功能。它的配置和AppStream类似,也使用了阿里云的镜像源。

通过配置这两个yum源,可以方便地安装和更新CentOS 8.5.2111版本的软件包。

image
http://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/?spm=a2c6h.25603864.0.0.bd1d5fa9xNdnYu
http://mirrors.aliyun.com/centos/8.5.2111/BaseOS/x86_64/os/?spm=a2c6h.25603864.0.0.59655aa3BAnOq7
https://mirrors.aliyun.com/centos/7/os/x86_64/?spm=a2c6h.25603864.0.0.68b44d00HuNI1D

Dockerfile常用指令

http://mirrors.ustc.edu.cn/centos/7/
https://codeantenna.com/a/LTy5w9REpB
国内yum源:
阿里yum源:http://mirrors.aliyun.com/repo/
163(网易)yum源: http://mirrors.163.com/.help/
中科大的Linux安装镜像源:http://centos.ustc.edu.cn/
搜狐的Linux安装镜像源:http://mirrors.sohu.com/
北京首都在线科技:http://mirrors.yun-idc.com/


docker commit -m="centos7-yum" -a="cw" 66c8dfbb16e0 centos7-yum:v1
docker commit -m="centos8-yum" -a="gangshen" 5d0da3dc9764 centos8-yum:latest
centos7-yum
语法:docker commit -m="描述信息" -a="作者" 容器id 目标镜像名:[TAG]
 
docker commit -m="centos8-yum" -a="gangshen" 5d0da3dc9764 centos8-yum:latest
这个centos8-yum就是我们自己创建的拥有正常yum源centos8系统镜像,现在,我要使用dockerfile来创建出一个有着更多命令的镜像。

Dockerfile常用指令
FROM             # 基础镜像,一切从这里开始构建
MAINTAINER       # 镜像是谁写的, 姓名+邮箱
RUN              # 镜像构建的时候需要运行的命令
ADD              # 步骤,tomcat镜像,这个tomcat压缩包!添加内容 添加同目录
WORKDIR          # 镜像的工作目录
VOLUME           # 挂载的目录
EXPOSE           # 保留端口配置
CMD              # 指定这个容器启动的时候要运行的命令,只有最后一个会生效,可被替代。
ENTRYPOINT       # 指定这个容器启动的时候要运行的命令,可以追加命令
ONBUILD          # 当构建一个被继承 DockerFile 这个时候就会运行ONBUILD的指令,触发指令。
COPY             # 类似ADD,将我们文件拷贝到镜像中
ENV              # 构建的时候设置环境变量!

curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
[root@master ~]# vi /etc/resolv.conf 
nameserver 8.8.8.8
# 向resolv.conf文件中添加下面内容
nameserver 114.114.114.114


https://mirrors.aliyun.com/centos/7/os/x86_64/?spm=a2c6h.25603864.0.0.68b44d00HuNI1D
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base2.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://centos.ustc.edu.cn/CentOS-Base.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=3
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
阿里源(推荐):
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
网易源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-Base.repo


wget http://centos.ustc.edu.cn/CentOS-Base.repo


[root@f5f62bc14911 yum.repos.d]# cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


在该配置文件中,`mirrorlist`参数指定了一个URL,用于获取CentOS Plus软件仓库的镜像列表。在这个URL中,有一个`infra=$infra`的参数。

`infra`参数是一个变量,用于指定基础设施类型。在这个URL中,`$infra`是一个占位符,实际的值会根据具体情况进行替换。这个参数的作用是根据不同的基础设施类型,选择合适的镜像列表。

例如,如果`$infra`的值是`centos`,那么URL中的`infra=centos`会被替换为实际的值,比如`infra=centos7`。这样就可以根据不同的基础设施类型,获取相应的镜像列表。

通过使用`infra=$infra`参数,可以根据基础设施类型动态选择合适的镜像列表,以提供更好的下载速度和可靠性。


https://mirrors.ustc.edu.cn/centos/7/os
https://mirrors.ustc.edu.cn/centos/7/os/x86_64/
https://blog.csdn.net/studyingjay/article/details/128341662
https://blog.csdn.net/weixin_39094034/article/details/127561524

centos查看$releasever,$basearch
rpm -qi centos-release
arch



https://mirrors.ustc.edu.cn/centos/7/os
https://mirrors.ustc.edu.cn/centos/7/os/x86_64/
http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=centos
http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=centos7
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=centos
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=centos7
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=$infra
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=$infra

[INFO]
通用指令:
#help : 回复此帮助
#help 插件名: 回复指定插件的详细帮助
#model : 查看和设置全局模型
#set_openai_api_key api_key: 设置你的OpenAI私有api_key
#reset_openai_api_key : 重置为默认的api_key
#set_gpt_model : 设置你的私有模型
#reset_gpt_model : 重置你的私有模型
#gpt_model : 查询你使用的模型
#reset : 重置会话

目前可用插件有:
Apilot:发送特定指令以获取早报、查询天气、星座运势、快递信息等!
角色扮演:让机器人扮演不同的角色。
linkai:用于集成 LinkAI 提供的知识库、Midjourney绘画、文档总结对话等能力。
文字冒险:可以和机器人一起玩文字冒险游戏。
summary:聊天记录总结插件。




参考

https://blog.csdn.net/2302_77582029/article/details/132087541
https://blog.csdn.net/z2050025507/article/details/132070156

posted @ 2023-10-20 15:22  三里清风18  阅读(101)  评论(0)    收藏  举报