8.26-docker创建容器+打包镜像+docker文件的学习

一、回顾

创建容器:docker run -it --name a1 centos:latest /bin/bash 查看容器:docker ps(查看正在up的容器) docker ps -a(查看所有的容器) 切回宿主机:ctrl p q 启动容器:docker start a1 停止容器:docker stop a1 删除容器:docker rm a1 docker rm -f a1(强制删除容器) 如果容器正在运行,容器是无法删除的,如果容器没有删除,对应的镜像也无法删除 镜像的迁移: save:docker save -o centos.tar centos:latest  load:docker load -i centos.tar 生成镜像: export(通过容器生成tar包):docker export -o centos_httpd.tar a1  import(通过tar引入镜像):docker import -m httpd centos_httpd.tar centos:httpd获得镜像的ip地址: 1、进入镜像的bash:yum -y install iprouter,net-tools 2、使用exec指令:dockers exec a1 yum -y install iprouter,net-tools docker exec a1 ip add 3、直接使用inspect命令:docker inspect a1 端口映射 -p: docker run -it --name a2 -p80:80 centos:latest /bin/bash docker run -it --name a2 -p80 centos:latest /bin/bash 宿主会指定一个大于32767的端口给容器 docker ps -a 查看实际给予的端口 docker run -it --name a2 -p10.0.0.101::80 centos:latest /bin/bash 数据持久化: docker run -it --name a2 -v /zhenji:/rongqi centos:latest /bin/bash 

二、部署一个考试项目

# 1、将资源上传到服务器
[root@docker ~]# yum -y install unzip
[root@docker ~]# rz -E
rz waiting to receive.
[root@docker ~]# unzip project_exam_system.zip # 2、创建基础镜像
[root@docker ~]# systemctl start docker
[root@docker ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Image is up to date for centos:latest
docker.io/library/centos:latest# 3、在容器中修改yum源
[root@docker ~]# docker run -it --name a0 centos:latest /bin/bash
[root@d1d92bed0d9a /]# rm -rf /etc/yum.repos.d/*
[root@d1d92bed0d9a /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   5898      0 --:--:-- --:--:-- --:--:--  5898
[root@d1d92bed0d9a /]# yum clean all && yum makecache # 4、在容器中安装epel
[root@d1d92bed0d9a /]# yum -y install epel-release# 5、在容器中安装nginx
[root@d1d92bed0d9a /]# yum -y install nginx# 6、ctrl p q退出容器
[root@d1d92bed0d9a /]# [root@docker ~]# # 7、导出tar包
[root@docker ~]# docker export -o centos_nginx.tar a0
[root@docker ~]# ls
anaconda-ks.cfg         centos.tar      project_exam_system.sql        yum_httpd.tar
application.properties  centos_yum.tar  Project_ExamSystem-V1.0.0.war
centos_nginx.tar        dist            project_exam_system.zip# 8、引入tar包,成为镜像
[root@docker ~]# docker import -m "nginx" centos_nginx.tar centos:nginx
sha256:a0a4655eb590b16aace6c33d78862992ccdf615f1d517d236d173ff501086ff8# 9、查看镜像
[root@docker ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
centos       nginx     a0a4655eb590   18 seconds ago   366MB
centos       httpd     92dfb2054854   3 days ago       310MB
centos       yum       d79f0f2ff79e   3 days ago       260MB
mysql        latest    a82a8f162e18   4 weeks ago      586MB
centos       latest    5d0da3dc9764   2 years ago      231MB# 10、删除容器
[root@docker ~]# docker rm -f a0
a0# 11、创建新的容器,在创建的同时指定端口,以及挂载目录
[root@docker ~]# docker run -it --name a0 -p80:80/tcp -v /opt/:/usr/share/nginx/html centos:nginx /bin/bash# 12、在容器内部启动nginx服务
[root@8dea218de2f7 /]# nginx# 13、curl p q退出镜像
[root@8dea218de2f7 /]# [root@docker ~]# 
[root@docker ~]# ls /opt
containerd# 14、在宿主机上把dist目录中的文件复制到opt目录下
[root@docker ~]# cp -r dist/* /opt/
[root@docker ~]# ls /opt/
assets  containerd  favicon.ico  index.html
[root@docker ~]# curl localhost
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><link rel="icon" href="/favicon.ico"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Vite App</title><script type="module" crossorigin src="/assets/index-C4kAShR5.js"></script><link rel="stylesheet" crossorigin href="/assets/index-CSz7ARPP.css"></head><body><div id="app"></div></body>
</html>
[root@docker ~]# systemctl stop firewalld
[root@docker ~]# systemctl disable firewalld
# 15、浏览器查看并登录

三、mysql镜像管理

# 拉取mysql镜像
[root@docker ~]# 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:86cdfe832c81e39a89cfb63c3fde1683c41cc00ef91e67653c9c1df0ba80f454
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest# 查看镜像
[root@docker ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
centos       httpd     92dfb2054854   3 days ago    310MB
centos       yum       d79f0f2ff79e   3 days ago    260MB
mysql        latest    a82a8f162e18   4 weeks ago   586MB
centos       latest    5d0da3dc9764   2 years ago   231MB# 使用mysql镜像创建一个名为mysql01的容器,密码为root,用户为root,端口为3306
[root@docker ~]# docker run -d --name mysql01 -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:latest
87136ab0b9a66e8d11be350cc11848db7bec4f914e45b889f77ff00aaa5b50fb# -d 后台运行
# -e MYSQL_ROOT_PASSWRD=root 设置mysql密码
# -p 映射3306端口# 查看up状态的容器
[root@docker ~]# docker ps 
CONTAINER ID   IMAGE          COMMAND                   CREATED       STATUS       PORTS                                                  NAMES
87136ab0b9a6   mysql:latest   "docker-entrypoint.s…"   3 hours ago   Up 3 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql01[root@docker ~]# docker exec -it mysql01 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 8
Server version: 9.0.1 MySQL Community Server - GPLCopyright (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.mysql> exit
Bye
 运行sql文件

查看数据库和表

mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| mysql               |
| performance_schema  |
| project_exam_system |
| sys                 |
+---------------------+
5 rows in set (0.00 sec)mysql> use project_exam_system
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show tables;
+-------------------------------+
| Tables_in_project_exam_system |
+-------------------------------+
| admin                         |
| category                      |
| com_city                      |
| com_nation                    |
| course                        |
| dept                          |
| dept_student                  |
| exam                          |
| exam_dept                     |
| exam_process                  |
| loginlog                      |
| major                         |
| menu                          |
| paper                         |
| paper_topic                   |
| role                          |
| role_admin                    |
| role_menu                     |
| semester                      |
| student                       |
| teacher                       |
| topic                         |
| user                          |
+-------------------------------+
23 rows in set (0.00 sec)mysql> select * from user;
+-----+--------------+----------+--------+---------------------+----------+---------------------+--------+-------+
| id  | userName     | password | status | createTime          | createOr | editTime            | editOr | isDel |
+-----+--------------+----------+--------+---------------------+----------+---------------------+--------+-------+
|   1 | 21001189     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-22 22:04:44 | NULL   |     0 |
|   2 | 21001190     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21 09:45:05 | NULL   |     0 |
|   3 | 21001191     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21 09:45:05 | NULL   |     0 |
|   4 | 21001192     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21 09:45:05 | NULL   |     0 |
|   5 | 21001193     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21 09:45:05 | NULL   |     0 |
|   6 | 21001194     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21 09:45:05 | NULL   |     0 |
|   7 | 21001195     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21 09:45:05 | NULL   |     0 |
|   8 | 21001196     | 111111   |      0 | 2024-08-21 09:45:05 | NULL     | 2024-08-21

四、让容器和宿主机时间一致

让容器共享宿主机的/etc/localtime

[root@docker ~]# docker run -it --name c8 -v /etc/localtime:/etc/localtime centos:latest /bin/bash
[root@08f5525f8d55 /]# date
Mon Aug 26 14:39:46 CST 2024

五、exec语句

# 创建名称为c8的容器
[root@docker ~]# docker run -it --name c8 -v /etc/localtime:/etc/localtime centos:latest /bin/bash# 退出容器不中断-ctrl+p+q
[root@08f5525f8d55 /]# [root@docker ~]# # 使用exec命令执行ls命令
[root@docker ~]# docker exec c8 ls /
bin
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var# 使用exec命令执行yum clean all && yum makecache这条命令
[root@docker ~]# docker exec c8  yum clean all && yum makecache
0 files removed
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                           | 5.1 kB  00:00:00     * base: mirrors.aliyun.com* epel: repo.jing.rocks* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
a                                                              | 3.6 kB  00:00:00     
base                                                           | 3.6 kB  00:00:00     
docker-ce-stable                                               | 3.5 kB  00:00:00     
extras                                                         | 2.9 kB  00:00:00     
updates                                                        | 2.9 kB  00:00:00     
(1/13): a/other_db                                             | 2.5 MB  00:00:00     
(2/13): a/filelists_db                                         | 6.9 MB  00:00:01     
(3/13): docker-ce-stable/7/x86_64/filelists_db                 |  66 kB  00:00:00     
(4/13): docker-ce-stable/7/x86_64/other_db                     | 145 kB  00:00:01     
(5/13): epel/x86_64/prestodelta                                |  592 B  00:00:01     
(6/13): extras/7/x86_64/filelists_db                           | 305 kB  00:00:01     
(7/13): extras/7/x86_64/other_db                               | 154 kB  00:00:01     
(8/13): base/7/x86_64/other_db                                 | 2.6 MB  00:00:08     
(9/13): updates/7/x86_64/other_db                              | 1.6 MB  00:00:09     
(10/13): base/7/x86_64/filelists_db                            | 7.2 MB  00:00:34     
(11/13): updates/7/x86_64/filelists_db                         |  15 MB  00:00:59     
epel/x86_64/filelists_db       FAILED                                          07 ETA 
(12/13): epel/x86_64/other_db                                  | 4.1 MB  00:08:03     
(13/13): epel/x86_64/filelists_db                              |  15 MB  00:05:49     
元数据缓存已建立
  ​​

六、容器之间的依赖

容器域名

容器的ip不稳定

加link模块

--link  容器名:别名
# 查看容器
[root@docker ~]# docker ps -all
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES# 创建名为m0容器
[root@docker ~]# docker run -d --name m0 -e MYSQL_ROOT_PASSWORD=root mysql:latest 
e6390afa961b4a3d8a3b3ff1e204073c0af4c8fed96198441d58f775e982c1e1# 查看m0容器的ip
[root@docker ~]# docker inspect m0"Gateway": "172.17.0.1","IPAddress": "172.17.0.2","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"DriverOpts": null,"DNSNames": null# 使用link模块为m0容器创建名为mysqldb依赖的容器
[root@docker ~]# docker run -it --name c0 --link m0:mysqldb centos:latest  /bin/bash# 在这个容器中pingmysqldb,会发现ping到的地址是m0的容器
[root@6c8098650212 /]# 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.063 ms
64 bytes from mysqldb (172.17.0.2): icmp_seq=2 ttl=64 time=0.081 ms
^C
--- mysqldb ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.063/0.072/0.081/0.009 ms# 在容器中查看etc/hosts文件 就看到mysqldb对应的地址是m0的地址
[root@6c8098650212 /]# 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.2	mysqldb e6390afa961b m0
172.17.0.3	6c8098650212# 退出容器不中断
[root@6c8098650212 /]# [root@docker ~]# # 查看所有容器
[root@docker ~]# docker ps --all
CONTAINER ID   IMAGE           COMMAND                   CREATED         STATUS         PORTS                 NAMES
6c8098650212   centos:latest   "/bin/bash"               3 minutes ago   Up 3 minutes                         c0
e6390afa961b   mysql:latest    "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   3306/tcp, 33060/tcp   m0# 停止容器m0的运行,172.17.0.2这个ip地址就被让出来了
[root@docker ~]# docker stop m0
m0# 重新创建c1容器
[root@docker ~]# docker run -it --name c1 centos:latest  /bin/bash# 退出不中断
[root@337a08b8a20a /]# [root@docker ~]# # 查看容器c1的ip地址,就会看到c1占用了172.17.0.2这个地址
[root@docker ~]# docker inspect c1"Gateway": "172.17.0.1","IPAddress": "172.17.0.2","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"DriverOpts": null,"DNSNames": null# 启动m0容器
[root@docker ~]# docker start m0
m0# 查看m0的容器的地址,就看发现它的地址变成了172.17.0.4
[root@docker ~]# docker inspect m0"Gateway": "172.17.0.1","IPAddress": "172.17.0.4","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"DriverOpts": null,"DNSNames": null# 挂载c0容器的终端
[root@docker ~]# docker attach c0# 继续pingmysqldb,发现地址变成了172.17.0.4(m0现在的地址)
[root@6c8098650212 /]# ping mysqldb
PING mysqldb (172.17.0.4) 56(84) bytes of data.
64 bytes from mysqldb (172.17.0.4): icmp_seq=1 ttl=64 time=0.111 ms
64 bytes from mysqldb (172.17.0.4): icmp_seq=2 ttl=64 time=0.052 ms
64 bytes from mysqldb (172.17.0.4): icmp_seq=3 ttl=64 time=0.101 ms
^C
--- mysqldb ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.052/0.088/0.111/0.025 ms# 在c0容器中查看/etc/hosts文件,发现里面的地址也变成了172.17.0.4
[root@6c8098650212 /]# 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.4	mysqldb e6390afa961b m0
172.17.0.3	6c8098650212# 退出不中断c0容器
[root@6c8098650212 /]# read escape sequence# 查看所有容器
[root@docker ~]# docker ps --all
CONTAINER ID   IMAGE           COMMAND                   CREATED          STATUS         PORTS                 NAMES
337a08b8a20a   centos:latest   "/bin/bash"               5 minutes ago    Up 5 minutes                         c1
6c8098650212   centos:latest   "/bin/bash"               9 minutes ago    Up 9 minutes                         c0
e6390afa961b   mysql:latest    "docker-entrypoint.s…"   11 minutes ago   Up 3 minutes   3306/tcp, 33060/tcp   m0
[root@docker ~]# docker stop c0
c0
[root@docker ~]# docker stop c1
c1
[root@docker ~]# docker stop m0
m0# 因为c0依赖m0,所以先启动被依赖的
[root@docker ~]# docker start c0
Error response from daemon: Cannot link to a non running container: /m0 AS /c0/mysqldb
Error: failed to start containers: c0# 先启动被依赖的容器
[root@docker ~]# docker start m0
m0# 再启动主动依赖的容器
[root@docker ~]# docker start c0
c0

小结:docker容器的ip地址不固定,如果要作为服务器使用,就必须能够直接访问服务,不能直接使用ip,为容器设置域名,做端口映射也能保证,确定是一旦停用之后端口被占用,就无法再次启动了

2.doker run --link ,容器的名称或者是id:自定义域名

3.被link容器必须处于启动状态,否则当前容器无法启

七、docker文件

停止docker服务
[root@docker ~]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:docker.socket# 进到/var/lib/docker目录下
[root@docker ~]# cd /var/lib/docker/
[root@docker docker]# ls
buildkit    engine-id  network   plugins   swarm  volumes
containers  image      overlay2  runtimes  tmp# 进到overlay2目录下
[root@docker docker]# cd overlay2/# 这些就是镜像和创建的容器
[root@docker overlay2]# ls
00332a9bd8355d76ca2d7273fc36abc55005c3f7e9ea99de4f28cc0f8d671c70
0e3f2d728c00d19f087019b9c153cb64e545733396b74552ba291cba3bfd0179
2fd26d35d6b387e52918f623dd35ebf137bdf660811fca395878d0f1a8cb0cb2
4448856ec7b6f553a449484292e7d7e428146e741b0443eae3bbddecc8d8954a
4448856ec7b6f553a449484292e7d7e428146e741b0443eae3bbddecc8d8954a-init
45a913457c95069ec4ee6c661fed0550de5e47264d04dc87975125bc4e97028f
60266e2b47ee1c7aae2cd1357f4dc5cac79042838a826fe1f9614dca8a8f948a
629bd34c6a92d5cb2b14fbbde998e2ad8e1fa3082d606589711d19781aabd43d
6f4cc31b4373e6edc88448de17eadcb7305279a61426b6463ff73e36f128e9a4
7b1ebd4b9c0adff07edfe76ff1a9ee30cf8800086dd955e923d3de349a59e6ad
7b1ebd4b9c0adff07edfe76ff1a9ee30cf8800086dd955e923d3de349a59e6ad-init
8cc2d6fcd7fd4102bbc47d61e2c804bfe3df6e945ba1ab09958dfbb9d51b35d1
8cc2d6fcd7fd4102bbc47d61e2c804bfe3df6e945ba1ab09958dfbb9d51b35d1-init
98021934d740dcde71e3cc6f1b6e6d2d4ccb829100600fec612e186fedf6ca02
9c7e62ffb3fa89bc9cc947020fd8c94a2b09401aa0ace4748bbef9f9cca8da4f
a2a47749e86aded67a82094e63c639a43bcb48c83e561cbb8096fb04fa11d23c
backingFsBlockDev
c1276ed5fa7657bf06ab97225ac522057bfbe0532db3b733455d3fa68d44344a
c1276ed5fa7657bf06ab97225ac522057bfbe0532db3b733455d3fa68d44344a-init
c69ce12a6a86fbf63f1efbc20aa7a1609834a2bb66b665b4c1c28e2ecc8ce886
d7985a6af5f182bf09f004ad9cbd578d3b2775821c4d1569ca10bdc9390dbea9
eed0e720b5b09a7840b16e666f10bd2bb16d00dc465cf414fd72bdf3c6fd9f49
eed0e720b5b09a7840b16e666f10bd2bb16d00dc465cf414fd72bdf3c6fd9f49-init
f538b28aac30b79bd465d6628306db7cf148b227b987a2fdead5b1f9aae6f16d
f9271f08918724184b1bdb5c22157def0fb7ac8569a59de9df953e1d79d32092
l
[root@docker overlay2]# cd# 删掉/var/lib/docker/这个目录
[root@docker ~]# rm -rf /var/lib/docker/# 启动docker服务
[root@docker ~]# systemctl start docker# 这个文件又会被重新创建
[root@docker ~]# ls /var/lib/docker/
buildkit    engine-id  network   plugins   swarm  volumes
containers  image      overlay2  runtimes  tmp# 查看镜像-发现没有
[root@docker ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE# 查看容器-也没有
[root@docker ~]# docker ps --all
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES# 查看/var/lib/docker/overlay2/目录,只有这两个文件
[root@docker ~]# ls /var/lib/docker/overlay2/
backingFsBlockDev  l# 上传centos镜像
[root@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@docker ~]# ls /var/lib/docker/overlay2/
951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5  l
backingFsBlockDev# 查看这个镜像中有什么
[root@docker ~]# ls /var/lib/docker/overlay2/951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5/
diff  link# 查看镜像的diff文件,会发现和linux系统一样
[root@docker ~]# ls /var/lib/docker/overlay2/951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5/diff
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr# 使用centos镜像创建容器
[root@docker ~]# docker run -it --name c0 centos:latest /bin/bash# 使用ctrl+p+q退出容器
[root@d854380d0f54 /]# [root@docker ~]# # 再次查看这个文件看有什么变化
[root@docker ~]# ls /var/lib/docker/overlay2/
951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5
backingFsBlockDev
f893e9d148c1ca1c5ed9e950eb1217c2aef1b89457a7407ffcd35a51f67a99f7
f893e9d148c1ca1c5ed9e950eb1217c2aef1b89457a7407ffcd35a51f67a99f7-init
l
[root@docker ~]# ls /var/lib/docker/overlay2/f893e9d148c1ca1c5ed9e950eb1217c2aef1b89457a7407ffcd35a51f67a99f7
diff  link  lower  merged  work# 使用docker的exec命令给c0容器创建一个zhangsan.txt文件
[root@docker ~]# docker exec c0 dd if=/dev/zero of=/zhangsan.txt bs=10M count=100
100+0 records in
100+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 1.16346 s, 901 MB/s# 查看c0容器的文件,就会看到创建的zhangsan.txt文件
[root@docker ~]# ls /var/lib/docker/overlay2/f893e9d148c1ca1c5ed9e950eb1217c2aef1b89457a7407ffcd35a51f67a99f7/merged/
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr  zhangsan.txt
[root@docker ~]# 

小结:

1.在docker daemon初始状态(没有状态的时候)/var/lib/docker不存在

2.当docker daemon服务器自启动创建docker目录

3.在没有镜像的情况下,查看overlay2这个目录是只有两个文件,管道文件,目录(管理镜像和容器的软链接的目录)

4.当我们pull一个镜像之后 /var/lib/docker/overlay2 下就有一个新的目录,这个目录就是镜像的基础目录,这个新的目录就是镜像,就是不可读的层

八、基础镜像制作

1.进程目录

[root@localhost ~]# ls /proc/
1     1531  279  385  5    657        crypto       kmsg          scsi
10    1535  28   386  512  664        devices      kpagecount    self
1014  1554  281  387  560  673        diskstats    kpageflags    slabinfo
1016  16    282  388  562  677        dma          loadavg       softirqs
1017  17    285  389  564  693        driver       locks         stat
11    18    286  390  565  7          execdomains  mdstat        swaps
1175  19    288  391  567  8          fb           meminfo       sys
1181  2     29   392  569  88         filesystems  misc          sysrq-trigger
1288  20    3    393  57   9          fs           modules       sysvipc
13    21    30   394  574  acpi       interrupts   mounts        timer_list
1316  263   359  40   578  asound     iomem        mpt           timer_stats
14    265   360  41   616  buddyinfo  ioports      mtrr          tty
15    268   370  42   639  bus        irq          net           uptime
1506  27    371  44   642  cgroups    kallsyms     pagetypeinfo  version
1511  275   38   460  643  cmdline    kcore        partitions    vmallocinfo
1529  276   383  483  644  consoles   keys         sched_debug   vmstat
1530  277   384  494  647  cpuinfo    key-users    schedstat     zoneinfo

2.sys目录是内核文件保存位置,不允许修改

[root@localhost ~]# cd /sys/
[root@localhost sys]# mkdir abc
mkdir: 无法创建目录"abc": 不允许的操作
[root@localhost sys]# 

3.排除以上两个目录,远程打包其他目录

[root@localhost~]# tar --numeric-owner --exclude=/proc --exclude=/sys -cvf haha.tar /# 将打包好的镜像传到docker主机上
[root@localhost~]# scp haha.tar root@192.1638.2.30:~

4.加载镜像

[root@docker ~]# ls
anaconda-ks.cfg         haha.tar    
[root@docker ~]# docker import -m "维护世界和平" haha.tar ha:v0

5.查看镜像

[root@docker ~]# docker images

6.使用镜像创建容器

[root@docker ~]# docker run -it --name ha01 ha:v0 /bin/bash
[root@5eaf8dd31774 /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@5eaf8dd31774 /]# cd
[root@5eaf8dd31774 ~]# ls
anaconda-ks.cfg  anaconda-post.log  original-ks.cfg
[root@5eaf8dd31774 ~]# cd /etc/yum.repos.d/
[root@5eaf8dd31774 yum.repos.d]# ls
CentOS-Base.repo   epel-playground.repo       epel-testing.repo
epel-modular.repo  epel-testing-modular.repo  epel.repo

九、应用镜像

将容器导出镜像-commit

[root@docker ~]# ls /var/lib/docker/overlay2/
951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5  l
backingFsBlockDev# 创建c0容器
[root@docker ~]# docker run -it --name c0 centos:latest /bin/bash# 清空仓库
[root@200554f77ada /]# rm -rf /etc/yum.repos.d/*# 安装阿里云镜像
[root@200554f77ada /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   4137      0 --:--:-- --:--:-- --:--:--  4130# 清理且建立缓存
[root@200554f77ada /]# yum clean all && yum makecache
Failed to set locale, defaulting to C.UTF-8
0 files removed
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com           591 kB/s | 4.6 MB     00:07    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com         9.7 kB/s |  10 kB     00:01    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com      406 kB/s | 8.4 MB     00:21    
Metadata cache created.# 安装epel
[root@200554f77ada /]# yum -y install epel-release# 安装httpd
[root@200554f77ada /]# yum -y install httpd # 退出不中断
[root@200554f77ada /]# [root@docker ~]# # 导出httpd镜像
[root@docker ~]# docker commit c0 centos:httpd
sha256:5fa4e3480590e0548419b770a52acf565729c1795cba386315a484e05a5c1e4d
[root@docker ~]# ls /var/lib/docker/overlay2/
4364fe8cf78dd976b842e3d6f7832640b8fd624928665cff2fa4b3d57506490c
951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5
backingFsBlockDev
d94e1199536123c1dfb61d7de10b9d599898e59bf627005939d8392cb1da526f
d94e1199536123c1dfb61d7de10b9d599898e59bf627005939d8392cb1da526f-init
l# 停止c0容器
[root@docker ~]# docker stop c0
c0
[root@docker ~]# ls /var/lib/docker/overlay2/
4364fe8cf78dd976b842e3d6f7832640b8fd624928665cff2fa4b3d57506490c
951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5
backingFsBlockDev
d94e1199536123c1dfb61d7de10b9d599898e59bf627005939d8392cb1da526f
d94e1199536123c1dfb61d7de10b9d599898e59bf627005939d8392cb1da526f-init
l# 删除c0容器
[root@docker ~]# docker rm c0
c0
[root@docker ~]# ls /var/lib/docker/overlay2/
4364fe8cf78dd976b842e3d6f7832640b8fd624928665cff2fa4b3d57506490c  backingFsBlockDev
951ab11df405924a3e43fc6b1f56b20b528152a937aaa863c6203305794520a5  l# 查看镜像
[root@docker ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
centos       httpd     5fa4e3480590   About a minute ago   320MB
centos       latest    5d0da3dc9764   2 years ago          231MB
[root@docker ~]# ls /var/lib/docker/overlay2/4364fe8cf78dd976b842e3d6f7832640b8fd624928665cff2fa4b3d57506490c/diff/
etc  run  tmp  usr  var# 查看httpd镜像的仓库
[root@docker ~]# ls /var/lib/docker/overlay2/4364fe8cf78dd976b842e3d6f7832640b8fd624928665cff2fa4b3d57506490c/diff/etc/yum.repos.d/
CentOS-Base.repo                     CentOS-Linux-Media.repo
CentOS-Linux-AppStream.repo          CentOS-Linux-Plus.repo
CentOS-Linux-BaseOS.repo             CentOS-Linux-PowerTools.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Sources.repo
CentOS-Linux-Debuginfo.repo          epel-modular.repo
CentOS-Linux-Devel.repo              epel-playground.repo
CentOS-Linux-Extras.repo             epel.repo
CentOS-Linux-FastTrack.repo          epel-testing-modular.repo
CentOS-Linux-HighAvailability.repo   epel-testing.repo

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/412429.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

KEIL Stm32 bin文件生成的两种方法以及报错的处理

Keil里生成bin文件的方法有两种&#xff0c;记录如下&#xff0c;以免忘记~ 首先&#xff0c;在Keil主页面&#xff0c;点击如下按钮&#xff0c;打开Options for Target ‘target 1’对话框&#xff0c;并选择User标签页。 其次&#xff0c;通过在 User标签页 设置 “After B…

react-native框架下,集成字体并应用全局

一、存放字体文件 将自定义字体文件&#xff08;例如 .ttf 或 .otf 文件&#xff09;放入项目的 assets/fonts 目录中。如果没有这个目录&#xff0c;可以手动创建。 二、配置字体 在项目根目录下建一个文件&#xff1a;react-native.config.js&#xff0c;文件内容如下&…

等保测评的五大误区与应对策略

等保测评&#xff08;信息安全等级保护测评&#xff09;作为确保信息系统安全的重要环节&#xff0c;常常伴随着一些常见的误区&#xff0c;这些误区可能导致组织在实施等保工作时偏离正确方向&#xff0c;增加合规风险。以下是等保测评中的五大常见误区及其应对策略。 一、误区…

zookeeper服务搭建

zookeeper服务搭建 前言1. 前置准备2. 下载和解压Zookeeper3. 配置环境变量4. 编辑Zookeeper配置文件5. 配置Zookeeper节点ID6. 配置好的Zookeeper分发到其他节点7. 启动Zookeeper集群参考博客 前言 Zookeeper是一个开源的分布式协调服务&#xff0c;主要用于解决分布式应用中的…

Leetcode面试经典150题-82.删除排序链表中的重复元素II前序-83.删除排序链表中的重复元素

解法都在代码里&#xff0c;不懂就留言或者私信&#xff0c;比第一题稍微难点 题目比较简单&#xff0c;真实面试中82和83都出现过&#xff0c;83偏多&#xff0c;先有个基础&#xff0c;马上分析82 /*** Definition for singly-linked list.* public class ListNode {* …

视频智能分析厨帽检测算法,厨帽检测算法全套源码、样本和模型展示

厨帽检测算法是一种基于人工智能和计算机视觉技术的系统&#xff0c;旨在自动检测厨师是否佩戴了符合规范的厨帽。该算法通过分析视频流或图像数据&#xff0c;实时识别厨帽的佩戴情况&#xff0c;从而帮助餐饮企业确保员工的着装符合卫生标准。这一技术广泛应用于餐馆、厨房、…

19050 牛牛打气球

### 思路 1. **输入读取**&#xff1a; - 读取 n&#xff0c;a 和 b。 - 读取每个气球的坚韧度。 2. **计算最少释放次数**&#xff1a; - 使用二分查找来确定最少的释放次数。 - 每次释放武器时&#xff0c;选择一个气球多承受 a 点伤害&#xff0c;其他气球承受…

春秋云镜initial

场景介绍 场景地址&#xff1a;仿真场景-专业徽章 (ichunqiu.com) 靶标介绍&#xff1a; Initial是一套难度为简单的靶场环境&#xff0c;完成该挑战可以帮助玩家初步认识内网渗透的简单流程。该靶场只有一个flag&#xff0c;各部分位于不同的机器上。 网络拓扑&#xff1a;&…

WebSocket通信学习笔记

1 简介 WebSocket是一种全双工通信协议&#xff0c;它允许客户端和服务器之间建立持久化的双向连接&#xff0c;从而在不频繁创建HTTP请求的情况下进行实时数据传输。与传统的HTTP协议相比&#xff0c;WebSocket更适合需要实时数据更新的应用场景&#xff0c;如聊天应用、实时…

【Kafka】Windows下安装Kafka(全面)

目录 1.前提条件 2.下载 3.安装 4.环境变量配置 5.验证 1.前提条件 1.先安装zookeeper&#xff1a; 【Zookeeper】Windows下安装Zookeeper&#xff08;全面&#xff09;-CSDN博客https://blog.csdn.net/weixin_57259781/article/details/141679454 2.还需要安装scala: …

虚幻5|技能栏UI优化(2)——优化技能UI并实现技能栏的拖拽操作

这篇文章里&#xff0c;前情提要&#xff0c;文章里的序列变量应命名为序号&#xff0c;我命名错了&#xff0c;虽然不差&#xff0c;但为了后面更好的理解 一.刷新技能栏&#xff0c;用于刷新上一章文章的初始化技能栏 1.打开技能栏格子&#xff0c;打开图表&#xff0c;添加…

【数学建模学习手册】python基本入门使用

本专栏内容为&#xff1a;数学建模原理 记录学习数学建模 &#x1f493;博主csdn个人主页&#xff1a;小小unicorn ⏩专栏分类&#xff1a;数学建模 &#x1f69a;代码仓库&#xff1a;小小unicorn的代码仓库&#x1f69a; &#x1f339;&#x1f339;&#x1f339;关注我带你学…

Cycle inside Runner; building could produce unreliable results.

报错 Showing Recent Messages Cycle inside Runner; building could produce unreliable results. Cycle details: → Target Runner ○ That command depends on command in Target Runner: script phase “Thin Binary” ○ Target Runner has process command with outpu…

Oracle taf高级特性使用

0、taf介绍 TAF是Oracle数据库提供的一个高级特性&#xff0c;旨在实现应用程序在数据库连接中断时的透明重连。它允许应用程序在数据库故障发生时&#xff0c;无需修改代码或手动干预&#xff0c;就能自动连接到新的数据库实例&#xff0c;保证了事务的连续性和应用的高可用性…

Python编码—掌握Python与Kubernetes:构建高效微服务架构

&#x1f31f;&#x1f31f; 欢迎来到我的技术小筑&#xff0c;一个专为技术探索者打造的交流空间。在这里&#xff0c;我们不仅分享代码的智慧&#xff0c;还探讨技术的深度与广度。无论您是资深开发者还是技术新手&#xff0c;这里都有一片属于您的天空。让我们在知识的海洋中…

开源搜索引擎之Solr

Apache Solr 是一个开源的企业级搜索平台&#xff0c;构建在 Apache Lucene 之上&#xff0c;提供了强大的全文搜索、实时索引和分布式搜索能力。Solr 被广泛用于构建高性能的搜索应用程序&#xff0c;支持从简单的搜索引擎到复杂的数据分析平台等多种场景。以下是对 Apache So…

Linux学习笔记(4)----Debian压力测试方法

使用命令行终端压力测试需要两个实用工具&#xff1a;s-tui和stress sudo apt install s-tui stress 安装完成后&#xff0c;在终端中启动 s-tui实用工具&#xff1a; s-tui 执行后如下图&#xff1a; 你可以使用鼠标或键盘箭头键浏览菜单&#xff0c;然后点击“压力选项(Str…

类在JVM中的工作原理

文章目录 引言I 类在JVM中的工作原理class文件的结构类的生命周期II JVM运行时数据区堆栈的意义栈帧内部结构堆III 在JIT中比较常见的优化手段引言 类是一种抽象概念,它是一种模板,用来定义一类事物的属性和行为。类是面向对象编程的基础,它是一种抽象的概念,代表一类事物…

科技赋能 重塑未来医疗丨共谋医疗信息化新方向,2024东北医院信息网络大会圆满落幕!

近年来&#xff0c;随着我国医疗行业信息化的飞跃式发展&#xff0c;医疗信息化已经成为推动医疗行业高质量发展的重要力量之一。自2021年国家卫健委、中医药管理局联合印发《公立医院高质量发展促进行动&#xff08;2021-2025年&#xff09;》以来&#xff0c;各医疗机构将建设…

Ant Design Vue中Modal.confirm无法自动关闭

温馨tips:着急看解决方法可跳过碎碎念~ 前两天经理扔给我一个问题&#xff1a;“这个弹窗怎么关不上了&#xff1f;” 我怀着无所谓的心态&#xff1a;小意思啦&#xff0c;5分钟之内解决完~ …当然flag是不能随便乱立的 拉下来项目&#xff08;原神启动&#xff08;不是&…