docker(4)https://developer.aliyun.com/article/1530615
卷的继承和共享
容器1完成和宿主机的映射
[root@VM-12-17-centos host_data]# docker run -it --privileged=true -v /mydocker/u:/tmp/u --name u1 ubuntu /bin/bash root@5f08bb00999a:/# ls bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var root@5f08bb00999a:/# cd tem bash: cd: tem: No such file or directory root@5f08bb00999a:/# cd tmp/ root@5f08bb00999a:/tmp# ls u root@5f08bb00999a:/tmp# cd u root@5f08bb00999a:/tmp/u# ls root@5f08bb00999a:/tmp/u# touch u1ddata.txt root@5f08bb00999a:/tmp/u# ls u1ddata.txt root@5f08bb00999a:/tmp/u# [root@VM-12-17-centos host_data]# [root@VM-12-17-centos host_data]# ls aazhaolong.txt [root@VM-12-17-centos host_data]# cd / [root@VM-12-17-centos /]# ls bin cert_key.pem data etc jdk-8u171-linux-x64.tar.gz lib64 logs media mydocker patch root sbin sys test usr www zzyyuse boot cert.pem dev home lib log lost+found mnt opt proc run srv target tmp var zh [root@VM-12-17-centos /]# cd mydocker/u/ [root@VM-12-17-centos u]# ls u1ddata.txt [root@VM-12-17-centos u]#
容器2继承容器1的卷规则
docker run -it --privileged=true --volumes-from 父类 --name u2 ubuntu
docker: Error response from daemon: pull access denied for u2, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'. [root@VM-12-17-centos u]# docker run -it --privileged=true --volumes-from u1 --name u2 ubuntu root@e10f0df32d1b:/# [root@VM-12-17-centos u]# [root@VM-12-17-centos u]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e10f0df32d1b ubuntu "bash" 20 seconds ago Up 19 seconds u2 5f08bb00999a ubuntu "/bin/bash" 8 minutes ago Up 8 minutes u1 3c716482179e registry "/entrypoint.sh /etc…" 3 hours ago Up 3 hours 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp jolly_sanderson [root@VM-12-17-centos u]# docker run -it --privileged=true --volumes-from u1 --name u2 ubuntu docker: Error response from daemon: Conflict. The container name "/u2" is already in use by container "e10f0df32d1bde1459029eb083830253556887078ecb3b1cfa67d50aa5414a93". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'. [root@VM-12-17-centos u]# docker exec -it e10f0df32d1b /bin/bashe OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bashe": stat /bin/bashe: no such file or directory: unknown [root@VM-12-17-centos u]# docker exec -it e10f0df32d1b /bin/bash
主机2拥有主机1的共享的数据卷
并且主机2对共享卷做的修改自动同步到u1
root@e10f0df32d1b:/tmp/u# touch u2.txt root@e10f0df32d1b:/tmp/u# ls a.txt u1ddata.txt u2.txt root@e10f0df32d1b:/tmp/u# exit exit [root@VM-12-17-centos u]# ls a.txt u1ddata.txt u2.txt [root@VM-12-17-centos u]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e10f0df32d1b ubuntu "bash" 4 minutes ago Up 4 minutes u2 5f08bb00999a ubuntu "/bin/bash" 12 minutes ago Up 12 minutes u1 3c716482179e registry "/entrypoint.sh /etc…" 3 hours ago Up 3 hours 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp jolly_sanderson [root@VM-12-17-centos u]# ls a.txt u1ddata.txt u2.txt [root@VM-12-17-centos u]# docker exec -it 5f08bb00999a /bin/bash root@5f08bb00999a:/# ls bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var root@5f08bb00999a:/# cd tmp/u/ root@5f08bb00999a:/tmp/u# ls a.txt u1ddata.txt u2.txt root@5f08bb00999a:/tmp/u#
六,常规软件的安装
1.总体步骤
- 搜索镜像
- 拉取镜像
- 查看镜像
- 启动镜像 =>端口服务映射
- 停止容器
- 移除容器
2.安装Tomcat
1.docker hub上面查找tomcat镜像
2.从docker hub上拉取tomcat镜像到本地
3.docker images查看是否有拉取到的tomcat
4.使用tomcat镜像创建容器实例(也叫运行镜像)
docker run -it -p 8080:8080 tomcat
-p 小写,主机端口:docker容器端口
-P 大写,随机分配端口
i 交互
t 终端
d 后台
5.访问猫首页
docker exec -it 86e7df2cb2e9 /bin/bash 用于进入bash 而不是 运行tomcat
[root@VM-12-17-centos u]# docker exec -it 86e7df2cb2e9 /bin/bash root@86e7df2cb2e9:/usr/local/tomcat# ls BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work root@86e7df2cb2e9:/usr/local/tomcat# cd .. root@86e7df2cb2e9:/usr/local# ls bin etc games include lib man openjdk-11 sbin share src tomcat root@86e7df2cb2e9:/usr/local# cd / root@86e7df2cb2e9:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@86e7df2cb2e9:/# lsb_release bash: lsb_release: command not found root@86e7df2cb2e9:/# cat /etc/redhat-release cat: /etc/redhat-release: No such file or directory root@86e7df2cb2e9:/# lsb_release -a bash: lsb_release: command not found root@86e7df2cb2e9:/# java -version openjdk version "11.0.13" 2021-10-19 OpenJDK Runtime Environment 18.9 (build 11.0.13+8) OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8, mixed mode, sharing) root@86e7df2cb2e9:/#
6.免修改版说明
3.安装mysql
- docker hub上面查找mysql镜像
- 从docker hub上(阿里云加速器)拉取mysql镜像到本地标签为5.7
- 使用mysq15.7镜像创建容器(也叫运行镜像)
docker run --name some-mysql -e MYSQL_RO0T_PASSHORD=my-secret-pw -d mysql:tag
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0
编码问题
默认的编码
show VARIABLES Like 'CHARACTER%'
使用容器卷
docker run -d -p 3306:3306 --privileged=true -v /zzyyuse/mysql/log:/var/log/mysql -v /zzyyuse/mysql/data:/var/lib/mysql -v /zzyyuse/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:8.0
–privileged少加-会出现No port specified: :/tcp<empty>.
错误
在mysql/conf下面新建my.cnf
[client] default_character_set=utf8 [mysqld] collation_server = utf8_general_ci character_set_server = utf8
结论
4.安装redis
docker run -d -p 6379:6379 redis: 6.0.8
启动时读取这个配置文件
修改redis.conf