使用docker、编写dockerfile、httpd镜像,并启动镜像,创建httpd主页和分页。(2)

1.准备一台机子,准备源,下载docker-ce

bash 复制代码
vi /etc/yum.repo.d/Centos-7.repo  加入以下内容
 
 
[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
 
 
 
配置docker
vi /etc/yum.repos.d/docker.repo
 
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
 
 
 
安装docker
yum -y install docker-ce

2.创建一个dockerfile执行目录,使用dockerfile编写apache镜像。

bash 复制代码
#进入dockerfile 编写
FROM centos:7    #要看你现在docker images 里面有没有centos7镜像,
RUN yum -y install httpd -y
VOLUME ["/var/www/html"]  #卷
EXPOSE 80  #端口暴露
CMD ["/usr/sbin/httpd","-DFOREGROUND"]  #启动httpd
 

3.构建镜像,并运行容器(使用端口)。

bash 复制代码
#执行dockerfile编写的命令
docker build -t httpd:v1 .

#运行httpd端口暴露
docker run -d -p 8888:80 --name httpd httpd:v1

#使用macvlan指定ip,先创建macvlan
docker network create -d macvlan --subnet 192.168.10.0/24 --gateway 192.168.10.2 -o parent=ens33 macvlan2

#使用macvlan运行,并指定ip
docker run -d --net macvlan --ip 192.168.10.86 --name httpd2 httpd:v1

构建镜像成功。

启动镜像成功。

4.浏览器访问:

端口暴露访问:192.168.10.202:8888

ip访问:192.168.10.86(macvlan)

  1. 创建主页和分页,先找到数据卷的位置
bash 复制代码
#找查数据卷位置  (中间的89是容器的id简写)
 docker inspect 89 | grep Sou

#进入数据卷位置  
cd 
/var/lib/docker/volumes/b5275e14935d153586686436df235d85a1cb87f7926392f5d1028906648c5c04/_data

#创建一个主页文件
vi index.html 写入

hallo word

#在创建一个 yang.html 写入

333333333333

浏览器访问:192.168.10.202:8888 出现hallo word

192.168.10.202:8888/yang.html 出现33333333333

6.总结:以上就是一个使用dockerfile编写的httpd镜像,并构建镜像,使用端口暴露和macvlan启动镜像,创建httpd主页和分页。

相关推荐
Danileaf_Guo3 小时前
256台H100服务器算力中心的带外管理网络建设方案
运维·服务器
拾贰_C5 小时前
【Linux | Windows | Terminal Command】 Linux---grep | Windows--- findstr
linux·运维·服务器
bloglin999995 小时前
启动容器报错ls: cannot access ‘/docker-entrypoint-initdb.d/‘: Operation not permitted
docker·容器·eureka
songjxin6 小时前
离线部署kubernetes v1.34.3
云原生·容器·kubernetes
虹科网络安全6 小时前
艾体宝洞察 | 利用“隐形字符”的钓鱼邮件:传统防御为何失效,AI安全意识培训如何补上最后一道防线
运维·网络·安全
石像鬼₧魂石6 小时前
Kali Linux 网络端口深度扫描
linux·运维·网络
alengan6 小时前
linux上面写python3日志服务器
linux·运维·服务器
yBmZlQzJ7 小时前
免费内网穿透-端口转发配置介绍
运维·经验分享·docker·容器·1024程序员节
JH30737 小时前
docker 新手入门:10分钟搞定基础使用
运维·docker·容器
小卒过河01047 小时前
使用apache nifi 从数据库文件表路径拉取远程文件至远程服务器目的地址
运维·服务器·数据库