1、环境的安装
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
# 如果容器正在运⾏,容器是删除的,如果容器没有删除,对应的镜
像也⽆法删除
镜像的迁移
![](https://i-blog.csdnimg.cn/direct/9bcaf137642f4c0da525e83302ba575c.png)
生成镜像
![](https://i-blog.csdnimg.cn/direct/c4c8cbac132d42279911be1bafa4693c.png)
获得镜像ip地址
![](https://i-blog.csdnimg.cn/direct/48149f6fd0794a8da4d47030980454d3.png)
端口映射-p
![](https://i-blog.csdnimg.cn/direct/8cce1cebd5ce43888fd8c8a8c8f062af.png)
数据持久化
![](https://i-blog.csdnimg.cn/direct/3a2bc988db7e49d593fdbd1ce7c9bf1c.png)
线上考试系统的数据,虚拟化技术部署
1、部署前段服务器
# 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镜像
![](https://i-blog.csdnimg.cn/direct/0a5787128d0842439c9d7cf4977b91c8.png)
![](https://i-blog.csdnimg.cn/direct/0bc16d5c2eb84ab7994dff95fa6b7ef8.png)
4、创建镜像容器
![](https://i-blog.csdnimg.cn/direct/2beba3bc0ffb4a49ac02df7cccfb72bc.png)
5、管理mysql
![](https://i-blog.csdnimg.cn/direct/1a24e554d0634936acd07906afa7cef5.png)
在容器外执行容器内部的命令
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
![](https://i-blog.csdnimg.cn/direct/bba3e02c2231415e9ca99811bb5b7fb8.png)
![](https://i-blog.csdnimg.cn/direct/cd4dda4c1d404d1d95c3c29e94c9ab0e.png)
![](https://i-blog.csdnimg.cn/direct/7b2df8d1ea284de49a5d4c67555d22cb.png)
测试
![](https://i-blog.csdnimg.cn/direct/1cd9b1e6d56549f19128af77d94b2b6f.png)
![](https://i-blog.csdnimg.cn/direct/3fbc930f06e7493ba3b79c6900966b22.png)
测试:使用一个容器占用172.17.0.2,测试
![](https://i-blog.csdnimg.cn/direct/f37ef0ff62f74240a68934410ae4668f.png)
![](https://i-blog.csdnimg.cn/direct/b86ba8ca28c542d888cb4c5e451000c3.png)
每次启动都修改了/ets/hosts文件
![](https://i-blog.csdnimg.cn/direct/b44361ee9d5d49b5a1003609129b9909.png)
1.docker容器的ip地址是不固定,如果要作为服务器使⽤,就必须能
够直接访问服务,不能直接使⽤ip,为容器设置域名,做端⼝映射也
能保证,确定是⼀旦停⽤之后端⼝被占⽤,就⽆法再次启动了2.docker run --link. 容器的名称或者是id:⾃定义域名
3.被link容器必须处于启动状态,否则当前容器⽆法启动