Linux动手实践·1
根据马哥教育架构班课程第一周作业而来
题目要求
在两台服务器上安装kvm虚拟化,把其中一台的虚拟机迁移到另一台;
手动制作一个容器镜像创建成容器并正常运行。
操作实践
- KVM虚拟化
1 | 新建三个虚机,分别承担KVM两个节点和一个NFS主机的角色 |
- 通过DockerFile部署容器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[root@vms101 ~]# mkdir -p /opt/dockerfile/web/nginx
[root@vms101 ~]# cd /opt/dockerfile/web/nginx
[root@vms101 nginx]#
cat > Dockerfile<<EOF
My Dockerfile
FROM centos:7.9.2009
MAINTAINER sujingxuan "sujx@live.cn"
RUN yum makecache && yum install -y wget && rm -f /var/yum.repos.d/* && wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo &&yum install -y epel-release && sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo && sed -i "s/metalink/#metalink/g" /etc/yum.repos.d/epel.repo && sed -i "s@https\?://download.fedoraproject.org/pub@https://repo.huaweicloud.com@g" /etc/yum.repos.d/epel.repo &&yum makecache
RUN yum install -y vim wget pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop nginx
RUN rm -f /usr/share/nginx/html/index.html && RUN echo "Docker YUM Nginx" >> /usr/share/nginx/html/index.html
EXPOSE 80 443
CMD ["nginx","-g","daemon off;"]
EOF
生成镜像
root@vms101 nginx]# docker build -t sujx/nginx-yum-file:v1 ./
[+] Building 160.1s (7/7) FINISHED ………………
运行镜像
[root@vms101 nginx]# docker run -d --name nginx-dfile -p 80:80 sujx/nginx-yum-file:v1
7b1f4629ff4a451d95c0a5284a06633bb6ae4c66a27ffb28433563045bde2a51
验证镜像
[root@vms101 nginx]# curl 127.0.0.1
Docker YUM Nginx
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.