Kubernetes 管理员认证(CKA)考试笔记
Posted 山河已无恙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kubernetes 管理员认证(CKA)考试笔记相关的知识,希望对你有一定的参考价值。
写在前面
- 嗯,准备考
cka
证书,报了个班,花了一个月工资,好心疼呀,一定要考过去。 - 这篇博客是报班听课后整理的笔记,适合温习。
- 博文内容涉及
docker
,k8s
; - 写的有点多了,因为粘贴了代码,所以只能分开发布
- 本部分内容涉及
docker相关复习
,k8s集群搭建
- 博文设计镜像小伙伴有需要可以留言
生活的意义就是学着真实的活下去,生命的意义就是寻找生活的意义 -----山河已无恙
一、docker 基础
1、容器 ?= docker
容器是什么?docker是什么? 启动盘
小伙伴都不陌生,电脑系统坏了,开不了机,我们插一个启动盘
就可以了,这个启动盘里有一些基础的软件
,那么这里,我们用的启动盘,就可以理解是一个类似镜像的东东,这个启动盘在电脑上运行一个系统,这个win PE系统就是一个容器,这个系统运行需要的物理内存CPU都是从物理机获取,也就是我们开不了机的那个电脑。
那现实场景中,我们要多管理容器和镜像,要怎么办,不能一个镜像放到一个U盘里吧,这里我们 需要一个 runtime(运行时),即用于管理容器的一种软件,比如 runc lxc gvisor kata
这些,只能管理容器,不能管理镜像,他们被称为 低级别运行时。
低级别的运行时功能单一,不能管理镜像,这时候需要有 高级别的运行时,比如 docker podman containerd ..
,用来调用管理低级别运行时 runc 等,即能管理容器,也能管理镜像。k8s是用来管理高级别运行时的。
关闭屏保
setterm -blank 0
配置yum源
rm -rf /etc/yum.repos.d/
wget ftp://ftp.rhce.cc/k8s/* -P /etc/yum.repos.d/
配置docker加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2tefyfv7.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
使用国内仓库
华为云 | |
网易云 | |
阿里云 |
2.docker镜像管理
┌──(liruilong㉿Liruilong)-[/mnt/c/Users/lenovo]
└─$ ssh root@192.168.26.55
Last login: Fri Oct 1 16:39:16 2021 from 192.168.26.1
┌──[root@liruilongs.github.io]-[~]
└─$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2021-09-26 02:07:56 CST; 1 weeks 0 days ago
Docs: https://docs.docker.com
Main PID: 1004 (dockerd)
Memory: 136.1M
CGroup: /system.slice/docker.service
└─1004 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
。。。。。。。
┌──[root@liruilongs.github.io]-[~]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
┌──[root@liruilongs.github.io]-[~]
└─$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
┌──[root@liruilongs.github.io]-[~]
└─$
docker镜像管理 | |
---|---|
镜像的命名方式 | 默认docker.io, |
docker pull 镜像 | 拉镜像 |
docker tag 镜像 | 打标签,重命名,类似于linxu里的硬连接 |
docker rmi 镜像 | 删除 |
docker save 镜像名 > filename.tar | 保存,备份 |
docker load -i filename.tar | 导入 |
docker export 容器名 > filename.tar | 把容器导出为镜像: |
导入 cat filename.tar | docker import - 镜像名 |
docker history xxxx --no-trunc | 可以显示完整的构建内容 |
┌──[root@liruilongs.github.io]-[~]
└─$ docker images | grep -v TAG | awk '{print $1":"$2}'
nginx:latest
mysql:latest
备份所有镜像
docker images | grep -v TAG | awk '{print $1":"$2}' | xargs docker save >all.tar
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker images | grep -v TAG | awk '{print $1":"$2}' | xargs docker save >all.tar
┌──[root@liruilongs.github.io]-[~/docker]
└─$ ls
all.tar docker_images_util_202110032229_UCPY4C5k.sh
删除所有镜像
docker images | grep -v TAG | awk '{print $1":"$2}' | xargs docker rmi
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f8f4ffc8092c 5 days ago 133MB
mysql latest 2fe463762680 5 days ago 514MB
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker images | grep -v TAG | awk '{print $1":"$2}' | xargs docker rmi
Untagged: nginx:latest
Untagged: nginx@sha256:765e51caa9e739220d59c7f7a75508e77361b441dccf128483b7f5cce8306652
Deleted: sha256:f8f4ffc8092c956ddd6a3a64814f36882798065799b8aedeebedf2855af3395b
Deleted: sha256:f208904eecb00a0769d263e81b8234f741519fefa262482d106c321ddc9773df
Deleted: sha256:ed6dd2b44338215d30a589d7d36cb4ffd05eb28d2e663a23108d03b3ac273d27
Deleted: sha256:c9958d4f33715556566095ccc716e49175a1fded2fa759dbd747750a89453490
Deleted: sha256:c47815d475f74f82afb68ef7347b036957e7e1a1b0d71c300bdb4f5975163d6a
Deleted: sha256:3b06b30cf952c2f24b6eabdff61b633aa03e1367f1ace996260fc3e236991eec
Untagged: mysql:latest
Untagged: mysql@sha256:4fcf5df6c46c80db19675a5c067e737c1bc8b0e78e94e816a778ae2c6577213d
Deleted: sha256:2fe4637626805dc6df98d3dc17fa9b5035802dcbd3832ead172e3145cd7c07c2
Deleted: sha256:e00bdaa10222919253848d65585d53278a2f494ce8c6a445e5af0ebfe239b3b5
Deleted: sha256:83411745a5928b2a3c2b6510363218fb390329f824e04bab13573e7a752afd50
Deleted: sha256:e8e521a71a92aad623b250b0a192a22d54ad8bbeb943f7111026041dce20d94f
Deleted: sha256:024ee0ef78b28663bc07df401ae3a258ae012bd5f37c2960cf638ab4bc04fafd
Deleted: sha256:597139ec344c8cb622127618ae21345b96dd23e36b5d04b071a3fd92d207a2c0
Deleted: sha256:28909b85bd680fc47702edb647a06183ae5f3e3020f44ec0d125bf75936aa923
Deleted: sha256:4e007ef1e2a3e1e0ffb7c0ad8c9ea86d3d3064e360eaa16e7c8e10f514f68339
Deleted: sha256:b01d7bbbd5c0e2e5ae10de108aba7cd2d059bdd890814931f6192c97fc8aa984
Deleted: sha256:d98a368fc2299bfa2c34cc634fa9ca34bf1d035e0cca02e8c9f0a07700f18103
Deleted: sha256:95968d83b58ae5eec87e4c9027baa628d0e24e4acebea5d0f35eb1b957dd4672
Deleted: sha256:425adb901baf7d6686271d2ce9d42b8ca67e53cffa1bc05622fd0226ae40e9d8
Deleted: sha256:476baebdfbf7a68c50e979971fcd47d799d1b194bcf1f03c1c979e9262bcd364
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
┌──[root@liruilongs.github.io]-[~/docker]
导入所有镜像
docker load -i all.tar
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker load -i all.tar
476baebdfbf7: Loading layer 72.53MB/72.53MB
525950111558: Loading layer 64.97MB/64.97MB
0772cb25d5ca: Loading layer 3.072kB/3.072kB
6e109f6c2f99: Loading layer 4.096kB/4.096kB
88891187bdd7: Loading layer 3.584kB/3.584kB
65e1ea1dc98c: Loading layer 7.168kB/7.168kB
Loaded image: nginx:latest
f2f5bad82361: Loading layer 338.4kB/338.4kB
96fe563c6126: Loading layer 9.557MB/9.557MB
44bc6574c36f: Loading layer 4.202MB/4.202MB
e333ff907af7: Loading layer 2.048kB/2.048kB
4cffbf4e4fe3: Loading layer 53.77MB/53.77MB
42417c6d26fc: Loading layer 5.632kB/5.632kB
c786189c417d: Loading layer 3.584kB/3.584kB
2265f824a3a8: Loading layer 378.8MB/378.8MB
6eac57c056e6: Loading layer 5.632kB/5.632kB
92b76bd444bf: Loading layer 17.92kB/17.92kB
0b282e0f658a: Loading layer 1.536kB/1.536kB
Loaded image: mysql:latest
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f8f4ffc8092c 5 days ago 133MB
mysql latest 2fe463762680 5 days ago 514MB
┌──[root@liruilongs.github.io]-[~/docker]
└─$
一个mysql镜像会运行一个 mysql进程, CMD [“mysqld”]
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker history mysql
IMAGE CREATED CREATED BY SIZE COMMENT
2fe463762680 5 days ago /bin/sh -c #(nop) CMD ["mysqld"] 0B
<missing> 5 days ago /bin/sh -c #(nop) EXPOSE 3306 33060 0B
<missing> 5 days ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entry… 0B
<missing> 5 days ago /bin/sh -c ln -s usr/local/bin/docker-entryp… 34B
<missing> 5 days ago /bin/sh -c #(nop) COPY file:345a22fe55d3e678… 14.5kB
<missing> 5 days ago /bin/sh -c #(nop) COPY dir:2e040acc386ebd23b… 1.12kB
<missing> 5 days ago /bin/sh -c #(nop) VOLUME [/var/lib/mysql] 0B
<missing> 5 days ago /bin/sh -c { echo mysql-community-server m… 378MB
<missing> 5 days ago /bin/sh -c echo 'deb http://repo.mysql.com/a… 55B
<missing> 5 days ago /bin/sh -c #(nop) ENV MYSQL_VERSION=8.0.26-… 0B
<missing> 5 days ago /bin/sh -c #(nop) ENV MYSQL_MAJOR=8.0 0B
<missing> 5 days ago /bin/sh -c set -ex; key='A4A9406876FCBD3C45… 1.84kB
<missing> 5 days ago /bin/sh -c apt-get update && apt-get install… 52.2MB
<missing> 5 days ago /bin/sh -c mkdir /docker-entrypoint-initdb.d 0B
<missing> 5 days ago /bin/sh -c set -eux; savedAptMark="$(apt-ma… 4.17MB
<missing> 5 days ago /bin/sh -c #(nop) ENV GOSU_VERSION=1.12 0B
<missing> 5 days ago /bin/sh -c apt-get update && apt-get install… 9.34MB
<missing> 5 days ago /bin/sh -c groupadd -r mysql && useradd -r -… 329kB
<missing> 5 days ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 5 days ago /bin/sh -c #(nop) ADD file:99db7cfe7952a1c7a… 69.3MB
┌──[root@liruilongs.github.io]-[~/docker]
└─$
3.docker管理容器
命令 | 描述 |
---|---|
docker run 镜像 | 最简单的一个容器 |
docker run -it --rm hub.c.163.com/library/centos /bin/bash | 有终端,有交互 |
docker run -dit -h node --name=c1 镜像名 命令 | 加名字,创建后不进去,进入 --attach,不进入 --detach,守护进程方式 |
docker run -dit --restart=always 镜像名 命令 | 退出时,容器依然活跃,设置自动重启 |
docker run -it --rm 镜像名 命令 | 进程结束,删除 |
docker run -dit --restart=always -e 变量1=值1 -e 变量2=值2 镜像 | 变量传递 |
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -it --name=c1 centos
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@f418f094e0d8 /]# ls
bin etc lib lost+found mnt proc run srv tmp var
dev home lib64 media opt root sbin sys usr
[root@f418f094e0d8 /]# exit
exit
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f418f094e0d8 centos "/bin/bash" 51 seconds ago Exited (0) 4 seconds ago c1
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -it --restart=always --name=c2 centos
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@ecec30685687 /]# exit
exit
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ecec30685687 centos "/bin/bash" 5 seconds ago Up 1 second c2
f418f094e0d8 centos "/bin/bash" About a minute ago Exited (0) About a minute ago c1
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker rm c1
c1
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker rm c2
Error response from daemon: You cannot remove a running container ecec30685687c9f0af08ea721f6293a3fb635c8290bee3347bb54f11ff3e32fa. Stop the container before attempting removal or force remove
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -itd --restart=always --name=c2 centos
docker: Error response from daemon: Conflict. The container name "/c2" is already in use by container "ecec30685687c9f0af08ea721f6293a3fb635c8290bee3347bb54f11ff3e32fa". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -itd --restart=always --name=c3 centos
WARNING: IPv4 forwarding is disabled. Networking will not work.
97ffd93370d4e23e6a3d2e6a0c68030d482cabb8ab71b5ceffb4d703de3a6b0c
┌──[root@liruilongs.github.io]-[~/docker]
└─$
创建一个mysql容器
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -dit --name=db --restart=always -e MYSQL_ROOT_PASSWORD=liruilong -e MYSQL_DATABASE=blog mysql
WARNING: IPv4 forwarding is disabled. Networking will not work.
0a79be3ed7dbd9bdf19202cda74aa3b3db818bd23deca23248404c673c7e1ff7
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
0a79be3ed7db mysql "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" 17 minutes ago Up 17 minutes c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker logs db
2021-10-03 16:49:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
2021-10-03 16:49:41+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-10-03 16:49:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
2021-10-03 16:49:41+00:00 [Note] [Entrypoint]: Initializing database files
2021-10-03T16:49:41.391137Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.26) initializing of server in progress as process 41
2021-10-03T16:49:41.400419Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-03T16:49:42.345302Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-03T16:49:46.187521Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-10-03T16:49:46.188871Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-10-03T16:49:46.312124Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-10-03 16:49:55+00:00 [Note] [Entrypoint]: Database files initialized
2021-10-03 16:49:55+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/0a79be3ed7db.err
┌──[root@liruilongs.github.io]-[~/docker]
└─$
nginx 安装
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -dit --restart=always -p 80 nginx
WARNING: IPv4 forwarding is disabled. Networking will not work.
c7570bd68368f3e4c9a4c8fdce67845bcb5fee12d1cc785d6e448979592a691e
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 4 seconds ago Up 2 seconds 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" 20 minutes ago Up 20 minutes c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$
4.管理容器的常见命令
命令 | 描述 |
---|---|
docker exec xxxx 命令 | 新的进程进入容器 |
docker start xxxx | 启动容器 |
docker stop xxxxx | 停止容器 |
docker restart xxxxx | 重启容器,当需要重启服务的时候可以重启容器 |
docker top xxxxx | 查看进程 |
docker logs -f node | 日志 |
docker inspect 容器 | 容器详细信息,ip等 |
┌──[root@liruilongs.github.io]-[~/docker]
└─$ mysql -uroot -pliruilong -h172.17.0.2 -P3306
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker exec -it db /bin/bash
root@0a79be3ed7db:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 14
Server version: 8.0.26 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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.
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.02 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'liruilong';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
root@0a79be3ed7db:/# eixt
bash: eixt: command not found
root@0a79be3ed7db:/# exit
exit
┌──[root@liruilongs.github.io]-[~/docker]
└─$ mysql -uroot -pliruilong -h172.17.0.2 -P3306
Welcome to the MariaDB monitor. Commands end with ; or \\g.
Your MySQL connection id is 15
Server version: 8.0.26 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.
MySQL [(none)]> use blog
Database changed
MySQL [blog]>
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker top db
UID PID PPID C STIME TTY TIME CMD
polkitd 15911 15893 1 00:49 ? 00:00:45 mysqld
┌──[root@liruilongs.github.io]-[~/docker]
└─$
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 43 minutes ago Up 43 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 46 minutes ago Up 46 minutes 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" About an hour ago Up About an hour c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker stop db
db
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 43 minutes ago Up 43 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
97ffd93370d4 centos "/bin/bash" About an hour ago Up About an hour c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker start db
db
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 44 minutes ago Up 44 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 47 minutes ago Up 2 seconds 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" About an hour ago Up About an hour c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker restart db
db
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 44 minutes ago Up 44 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 47 minutes ago Up 2 seconds 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" About an hour ago Up About an hour c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$
删除所有容器
┌──[root@liruilongs.github.io]-[~]
└─$ docker ps | grep -v IMAGE
5b3557283314 nginx "/docker-entrypoint.…" About an hour ago Up About an hour 80/tcp web
c7570bd68368 nginx "/docker-entrypoint.…" 9 hours ago Up 9 hours 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 9 hours ago Up 8 hours 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" 9 hours ago Up 9 hours c3
┌──[root@liruilongs.github.io]-[~]
└─$ docker ps | grep -v IMAGE | awk '{print $1}'
5b3557283314
c7570bd68368
0a79be3ed7db
97ffd93370d4
┌──[root@liruilongs.github.io]-[~]
└─$ docker ps | grep -v IMAGE | awk '{print $1}'| xargs docker rm -f
5b3557283314
c7570bd68368
0a79be3ed7db
97ffd93370d4
┌──[root@liruilongs.github.io]-[~]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
┌──[root@liruilongs.github.io]-[~]
└─$
5.数据卷的使用
命令 | 描述 |
---|---|
docker run -dit --restart=always -v p_path1:c_path2 镜像名 命令 | 与端口映射类似,直接映射宿主机目录 |
docker run -dit --restart=always -v c_path2 镜像名 命令 | 当只写了一个的时候,可以通过 docker inspect 来查看映射,mounts属性 |
docker volume create v1 | 自定共享卷,然后挂载 |
数据会被写到容器层,删除容器,容器数据也会删除
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 44 minutes ago Up 44 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 47 minutes ago Up 2 seconds 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" About an hour ago Up About an hour c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ find / -name liruilong.html
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker exec -it c7570bd68368 /bin/bash
root@c7570bd68368:/# echo "liruilong" > liruilong.html
root@c7570bd68368:/# exit
exit
┌──[root@liruilongs.github.io]-[~/docker]
└─$ find / -name liruilong.html
/var/lib/docker/overlay2/56de0e042c7c5b9704df156b6473b528ca7468d8b1085cb43294f9111b270540/diff/liruilong.html
/var/lib/docker/overlay2/56de0e042c7c5b9704df156b6473b528ca7468d8b1085cb43294f9111b270540/merged/liruilong.html
┌──[root@liruilongs.github.io]-[~/docker]
└─$
docker run -itd --name=web -v /root/docker/liruilong:/liruilong:rw nginx
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7570bd68368 nginx "/docker-entrypoint.…" 8 hours ago Up 8 hours 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 8 hours ago Up 7 hours 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" 8 hours ago Up 8 hours
c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker rm -f web
web
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker run -itd --name=web -v /root/docker/liruilong:/liruilong:rw nginx
WARNING: IPv4 forwarding is disabled. Networking will not work.
5949fba8c9c810ed3a06fcf1bc8148aef22893ec99450cec2443534b2f9eb063
┌──[root@liruilongs.github.io]-[~/docker]
└─$ ls
all.tar docker_images_util_202110032229_UCPY4C5k.sh liruilong
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5949fba8c9c8 nginx "/docker-entrypoint.…" 57 seconds ago Up 4 seconds 80/tcp web
c7570bd68368 nginx "/docker-entrypoint.…" 8 hours ago Up 8 hours 0.0.0.0:49153->80/tcp, :::49153->80/tcp jovial_solomon
0a79be3ed7db mysql "docker-entrypoint.s…" 8 hours ago Up 7 hours 3306/tcp, 33060/tcp db
97ffd93370d4 centos "/bin/bash" 8 hours ago Up 8 hours c3
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker exec -it web /bin/bash
root@5949fba8c9c8:/# ls
bin docker-entrypoint.d home liruilong opt run sys var
boot docker-entrypoint.sh lib media proc sbin tmp
dev etc lib64 mnt root srv usr
root@5949fba8c9c8:/#
docker volume create v1
┌──[root@liruilongs.github.io]-[~/docker]
└─$
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker volume list
DRIVER VOLUME NAME
local 9e939eda6c4d8c574737905857d57014a1c4dda10eef77520e99804c7c67ac39
local 34f699eb0535315b651090afd90768f4e4cfa42acf920753de9015261424812c
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker volume create v1
v1
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker volume list
DRIVER VOLUME NAME
local 9e939eda6c4d8c574737905857d57014a1c4dda10eef77520e99804c7c67ac39
local 34f699eb0535315b651090afd90768f4e4cfa42acf920753de9015261424812c
local v1
┌──[root@liruilongs.github.io]-[~/docker]
└─$ docker volume inspect v1
[
{
"CreatedAt": "2021-10-04T08:46:55+08:00",
"Driver": "local",
以上是关于Kubernetes 管理员认证(CKA)考试笔记的主要内容,如果未能解决你的问题,请参考以下文章