云计算day32

docker容器==》k8s编排=〉openstack
存储 监控 ⽇志 以及其他的内容
回顾
1.环境的安装
cat << EOF | tee /etc/modules-load.d/k8s.conf
> overlay
> br_netfilter
> EOF
overllay
br_netfilter
cat << EOF | tee /etc/sysctl.d/k8s.conf
> net.bridge.bridge-nf-call-iptables = 1
> net.bridge.bridge-nf-call-ip6tables = 1
> net.ipv4.ip_forward = 1
> EOF

yum 镜像

yum 服务器和客户端2.镜像案例

启动服务

systemctl start docker.service

查看镜像

docker images
docker image ls

删除镜像

docker rmi centos:latest
docker rmi 5axxxx(img id)

在公共仓库查找镜像

docker search centos

拉取镜像

docker pull centos
2.管理容器 容器就是在镜像上添加了⼀个可写层

创建容器docker run -it --name c0 centos:latest /bin/bash

查看容器

docker ps # 查看up的容器
docker ps --all #查看所有的容器

切回宿主 ctrl p q

#启动容器
docker start c0 c1
#停⽤容器
docker stop c0 c1
#删除容器
docker rm c0 c1

如果容器正在运⾏,容器是删除的,如果容器没有删除,对应的镜

像也⽆法删除
镜像的迁移

save

docker save -o centos.tar centos:latest

load

docker save -i centos.tar⽣成镜像

export 通过容器⽣成tar

docker export centoshttpd.tar c0

import 通过tar引⼊镜像

docker import -m "dafdsfa" centoshtpd centos:httpd
docker images
获得镜像ip地址

进⼊到镜像的bash

yum install iprouter,net-tools
ip a

使⽤exec指令

docker exec 容器名称或者id yum -y install iproute
docker exec c0 ip a

直接使⽤inspect命令

dcoker inspoct c0
端⼝映射 -p数据持久化
线上考试系统的数据 虚拟化技术部署
1.部署前段服务器
docker run -it --name c0 -p80:80/tcp centos:latest
/bin/bash
docker run -it --name c1 -p80 centos:latest
/bin/bash # 宿主会指定⼀个⼤于等于3278的端⼝给容器
docker ps --all # 查看实际给予的端⼝
docker run -it --name c2 -p10.1.1.51::80
centos:latest /bin/bash
docker run -it --name c4 -v /opt/:/var/www/html/
centos:latest /bin/bash

1.将资源上传到服务器

scp -r dist/ root@192.168.71.50:~# 2创建基础容器 在服务器上
systemctl start docker.service
docker pull centos
docker run -it --name c0 centos:latest /bin/bash

3 在容器中修改yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-vault-
8.5.2111.repo
yum clean all && yum makecache

4.在容器中安装epel

yum -y install epel-release

5.在容器中安装nginx

yum -y install nginx

6.ctrl pq

7.导出tar包

docker export -o centos_nginx.tar

8.引⼊tar包,称为镜像

docker import -m "维护世界和平" centos_nginx.tar
centos:nginx

9.查看镜像

docker image ls
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED
SIZE
centos nginx 9afbddb29074 10 seconds
ago 366MBmysql latest a82a8f162e18 4 weeks ago
586MB
centos latest 5d0da3dc9764 2 years ago
231MB

10.停⽤c0容器,删除c0容器

11.创建新的centos nginx容器,在创建的同时指定端⼝,以及

挂载⽬录
docker run -it --name c0 -p80:80/tcp -v
/opt/:/usr/share/nginx/html centos:nginx /bin/bash

12在容器内部启动nginx服务

nginx
#ctrl p q

13 在宿主上把dist⽬录中的⽂件复制opt⽬录中

cp -r dist/* /opt
1.启动docker守护进程
[root@docker001 ~]# systemctl start docker.service2.搜索mysql镜像
[root@docker001 ~]# docker search mysql
NAME DESCRIPTION
STARS OFFICIAL
mysql MySQL is a widely used, open
source relation... 15322 [OK]
bitnami/mysql Bitnami container image for
MySQL 114
google/mysql MySQL server for Google
Compute Engine 25
elestio/mysql Mysql, verified and packaged
by Elestio 0
rapidfort/mysql RapidFort optimized, hardened
image for MySQL 25
circleci/mysql MySQL is a widely used, open
source relation... 30
ubuntu/mysql MySQL open source fast,
stable, multi-thread... 64
javanile/mysql MySQL for development
0
eclipse/mysql Mysql 5.7, curl, rsync
1
ilios/mysql Mysql configured for running
Ilios 1
cimg/mysql
3bitnamicharts/mysql
0
mirantis/mysql
0
docksal/mysql MySQL service images for
Docksal - https://d... 0
linuxserver/mysql A Mysql container, brought to
you by LinuxSe... 41
datajoint/mysql MySQL image pre-configured to
work smoothly ... 2
ddev/mysql ARM64 base images for ddev
dbserver-mysql-8.... 1
phpmyadmin phpMyAdmin - A web interface
for MySQL and M... 1017 [OK]
vulhub/mysql
0
drud/mysql
1
nasqueron/mysql
1
corpusops/mysql
https://github.com/corpusops/docker-images/ 0
jumpserver/mysql
1
openeuler/mysql
0encoflife/mysql
0
3.拉取mysql镜像
[root@docker001 ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
6e839ac3722d: Pull complete
ad912193ad5f: Pull complete
25d13d87fd8d: Pull complete
004d383c75ef: Pull complete
6d9bbc82a0b8: Pull complete
81fec07ea550: Pull complete
83357cb2d3a5: Pull complete
8ffe968b82c1: Pull complete
30dfd9a7ed57: Pull complete
35844ae33cbe: Pull complete
Digest:
sha256:86cdfe832c81e39a89cfb63c3fde1683c41cc00ef91e
67653c9c1df0ba80f454
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@docker001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED
SIZEcentos nginx 12fea1b890de 13 hours
ago 366MB
centos java17 b6bf774de7bb 14 hours
ago 550MB
centos_httpd v0 fffc96d791d5 39 hours
ago 309MB
centos_yum v0 191d9c84f461 39 hours
ago 260MB
mysql latest a82a8f162e18 4 weeks ago
586MB
centos latest 5d0da3dc9764 2 years ago
231MB
4.创建镜像容器
[root@docker001 ~]# docker run -d --name my01 -e
MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:latest
9338d672d3d819e5eb35fcf9fb5cd8fe88daf5a84b00ab0a4b3
3fc9b9ba87d8a

-d 后台运⾏,并输出hashcode

-e MYSQL_ROOT_PASSWORD=root 设置mysql密码

-p 映射3306端⼝

5.管理mysql[root@docker001 ~]# docker exec -it my01 mysql -
uroot -proot
mysql: [Warning] Using a password on the command
line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ;
or \g.
Your MySQL connection id is 9
Server version: 9.0.1 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its
affiliates.
Oracle is a registered trademark of Oracle
Corporation and/or its
affiliates. Other names may be trademarks of their
respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear
the current input statement.
让容器时间和宿主机时间⼀

[root@docker001 ~]# docker run -it --name c0
centos:nginx /bin/bash
[root@6caf88cce814 /]# date
Sat Aug 24 13:36:54 UTC 2024
[root@6caf88cce814 /]# [root@docker001 ~]#
[root@docker001 ~]# docker run -it --name c1 -v
/etc/localtime:/etc/localtime centos:nginx
/bin/bash
[root@f01eb51c8a59 /]# date
Sat Aug 24 21:38:29 CST 2024
[root@f01eb51c8a59 /]#
[root@docker001 ~]# docker exec c0 date
Sat Aug 24 13:40:14 UTC 2024
[root@docker001 ~]# docker exec c1 date
Sat Aug 24 21:40:19 CST 2024
让容器共享宿主的/etc/localtime
exec命令

容易内部已经安装的指令⽅可执⾏,否则⽆法执⾏

[root@docker001 ~]# docker exec c0 ifconfig
OCI runtime exec failed: exec failed: unable to
start container process: exec: "ifconfig":
executable file not found in $PATH: unknown
[root@docker001 ~]# docker exec c0 ls /
bin
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srvsys
tmp
usr
var
容器的ip地址不稳定 link
--link 容器名:别名
[root@docker001 ~]# docker run -it --name c0
centos:nginx /bin/bash
[root@20f05670b7df /]# [root@docker001 ~]#
[root@docker001 ~]# docker run -it --link
c0:mysqldb --name c1 centos:nginx /bin/bash
[root@ba46c0e4055d /]# ping mysqldb
PING mysqldb (172.17.0.2) 56(84) bytes of data.
64 bytes from mysqldb (172.17.0.2): icmp_seq=1
ttl=64 time=0.057 ms
64 bytes from mysqldb (172.17.0.2): icmp_seq=2
ttl=64 time=0.044 ms
64 bytes from mysqldb (172.17.0.2): icmp_seq=3
ttl=64 time=0.039 ms^C
--- mysqldb ping statistics ---
3 packets transmitted, 3 received, 0% packet loss,
time 2002ms
rtt min/avg/max/mdev = 0.039/0.046/0.057/0.010 ms
测试

暂停服务

[root@docker001 ~]# docker stop c0 c1
c0
c1

先启动主动依赖容器

[root@docker001 ~]# docker start c1

⽆法启动,提示被link的容器没有启动

Error response from daemon: Cannot link to a non
running container: /c0 AS /c1/mysqldb
Error: failed to start containers: c1
[root@docker001 ~]# docker start c1
Error response from daemon: Cannot link to a non
running container: /c0 AS /c1/mysqldb
Error: failed to start containers: c1

先启动被依赖的容器

[root@docker001 ~]# docker start c0
c0# 在启动主动依赖的容器
[root@docker001 ~]# docker start c1
c1
[root@docker001 ~]#
测试 使⽤⼀个容器占⽤172.17.0.2,测试

停⽤容器

[root@docker001 ~]# docker stop c0 c1
c0
c1

创建新容器 占⽤172.17.02

[root@docker001 ~]# docker run -it --name c2
centos:nginx /bin/bash
[root@2114e0e97441 /]# [root@docker001 ~]#

启动 c0 c1

[root@docker001 ~]# docker start c0 c1
c0
c1

在c1容器ping别名

[root@docker001 ~]# docker exec c1 ping mysqldb
PING mysqldb (172.17.0.3) 56(84) bytes of data.64 bytes from mysqldb (172.17.0.3): icmp_seq=1
ttl=64 time=0.157 ms
64 bytes from mysqldb (172.17.0.3): icmp_seq=2
ttl=64 time=0.037 ms
64 bytes from mysqldb (172.17.0.3): icmp_seq=3
ttl=64 time=0.056 ms
^C
[root@docker001 ~]#
每次启动都修改了/ets/hosts⽂件
[root@docker001 ~]# docker exec c1 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3 mysqldb 20f05670b7df c0
172.17.0.4 ba46c0e4055d
1.docker容器的ip地址是不固定,如果要作为服务器使⽤,就必须能
够直接访问服务,不能直接使⽤ip,为容器设置域名,做端⼝映射也
能保证,确定是⼀旦停⽤之后端⼝被占⽤,就⽆法再次启动了2.docker run --link. 容器的名称或者是id:⾃定义域名
3.被link容器必须处于启动状态,否则当前容器⽆法启动

  1. docker client向dcoker daemon 发送创建容器的请求 docker
    run
  2. docker daemon查找有⽆客户端需要的镜像
  3. 如果没有,就到容器的镜像仓库下载需要的镜像 pull
  4. 拿到容器镜像后,启动容器1.在docker daemo初始状态(没有镜像的时候) /var/lib/docker不
    存在
    2.当docker daemon服务器启动,会⾃动创建dock⽬录
    3.在没有镜像的情况下。查看overlay2这个⽬录是只有两个⽂件,
    管道⽂件 ,l⽬录(管理镜像和容器的软连接的⽬录)
    4.当我们pull⼀个镜像之后 /va r/lib/docker/overlay2下就有⼀个新
    的⽬录,这个⽬录就是cenonos的基础⽬录,这个新的⽬录就是镜
    像,就是不可读的层5.当我们使⽤这个镜像创建⼀个容器,在overlay2会添加2个⽬录,
    ⼀个是init⽬录,另外⼀个⽬录就是容器的可写层,⽤户对系统的修
    改都在可写层中进⾏
    1.进程⽬录
    2.sys⽬录是内核⽂件保存位置,不允许修改
    3.排除以上2个⽬录,并且将⽤户设置为数字
    [root@docker001 sys]# tar --numeric-owner --
    exclude=/proc --exclude=/sys -cvf centos7.tar /
    4.将项⽬移动到dockerserver主机上
    5.查看tar包[root@docker001 ~]# ls
    anaconda-ks.cfg centos7.tar centos_java17 frp
    initserver.sh jdk-17_linux-x64_bin.tar.gz
    5.加载镜像
    [root@docker001 ~]# docker import -m "说明0"
    centos7.tar me:me00
    6.查看镜像[root@docker001 ~]# docker images
    REPOSITORY TAG IMAGE ID CREATED
    SIZE
    me me00 64abc01ff8c4 3 minutes
    ago 2.55GB
    centos nginx 12fea1b890de 24 hours
    ago 366MB
    centos java17 b6bf774de7bb 24 hours
    ago 550MB
    centos_httpd v0 fffc96d791d5 2 days ago
    309MB
    centos_yum v0 191d9c84f461 2 days ago
    260MB
    mysql latest a82a8f162e18 4 weeks
    ago 586MB
    centos latest 5d0da3dc9764 2 years
    ago 231MB
    7.创建容器[root@docker001 ~]# docker run -it --name c00
    me:me00 /bin/bash
    [root@4199382c490f /]# ls
    bin dev home lib64 mnt proc run srv tmp
    var
    boot etc lib media opt root sbin sys usr
    [root@4199382c490f /]#
    1.根据基础镜像创建容器
    docker run -it --name c0 centos_yum:v0 /bin/bash
    2.安装应⽤
    yum -y install httpd
    3.ctrl p q
    4.docker commit
    [root@docker001 ~]# docker commit --help
    Usage: docker commit [OPTIONS] CONTAINER
    [REPOSITORY[:TAG]]
    Create a new image from a container's changes
    Aliases:
    docker container commit, docker commit
    Options:
    -a, --author string Author (e.g., "John
    Hannibal Smith <hannibal@a-team.com>") -c, --change list Apply Dockerfile
    instruction to the created image
    -m, --message string Commit message
    -p, --pause Pause container during
    commit (default true)
    [root@docker001 ~]# docker commit c0 centos:httpd
    sha256:bbf5ed97db84f87ec8cbc8e82297fe22f79ad437d60
    3f743840c0b7b62be4196
    [root@docker001 ~]# docker images
    REPOSITORY TAG IMAGE ID CREATED
    SIZE
    centos httpd bbf5ed97db84 3 minutes
    ago 340MB
    me me00 64abc01ff8c4 29 minutes
    ago 2.55GB
    centos nginx 12fea1b890de 24 hours
    ago 366MB
    centos java17 b6bf774de7bb 25 hours
    ago 550MB
    centos_httpd v0 fffc96d791d5 2 days ago
    309MB
    centos_yum v0 191d9c84f461 2 days ago
    260MB
    mysql latest a82a8f162e18 4 weeks
    ago 586MBcentos latest 5d0da3dc9764 2 years
    ago 231MB
相关推荐
企业管理8MSaaS13 小时前
如何选择适合Scrum团队的项目管理系统?
云计算·scrum
企业管理8MSaaS13 小时前
如何在 Scrum 管理中化解团队冲突?
云计算·scrum
正在走向自律1 天前
阿里云ESC服务器一次性全部迁移到另一个ESC
服务器·阿里云·云计算
OkeyProxy1 天前
HTTP、HTTPS和SOCKS5代理協議
网络协议·https·云计算·代理服务器·海外ip代理
小峰编程1 天前
独一无二,万字详谈——Linux之文件管理
linux·运维·服务器·云原生·云计算·ai原生
終不似少年遊*1 天前
华为云计算HCIE笔记04
网络·华为云·云计算·学习笔记·hcie·认证·数据中心
神秘的土鸡1 天前
LGMRec:结合局部与全局图学习的多模态推荐系统
目标检测·计算机视觉·云计算
♡喜欢做梦1 天前
腾讯云云开发 Copilot 深度探索与实战分享
云计算·腾讯云·copilot·玩转云开发 copilot
HUIBUR科技1 天前
人工智能与云计算的结合:如何释放数据的无限潜力?
人工智能·ai·云计算
云计算DevOps-韩老师1 天前
【网络云计算】2024第52周-每日【2024/12/23】小测-理论&实操-解析
linux·运维·服务器·开发语言·网络·云计算·perl