docker⽂件存放路径,修改端⼝映射操作⽅式
如何获取容器的启动命令
容器早已创建好,如何得知它的启动参数(数据挂载到哪)
#假设通过如下命令启动了⼀个容器
docker run -d --name mysql_cdh \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=123456 \
-v mysql-data:/var/lib/mysql \
--restart=always \
mysql:5.5 --character-set-server=utf8
#如何通过容器名得知启动参数
[root@jenkins ~]# docker inspect mysql_cdh
[
{
"Id": "3aad772538b5e86705d3358362517a08d53f951aa6522e2881321135f05c8872",
"Created": "2019-09-25T01:43:37.720505875Z",
"Path": "docker-entrypoint.sh",
"Args": [
"--character-set-server=utf8"
],
...
"Name": "/mysql_cdh",
mysql默认端口
"HostConfig": {
"Binds": [
"mysql-data:/var/lib/mysql"
],
...
"NetworkMode": "default",
"PortBindings": {
"3306/tcp": [
{
"HostIp": "",
"HostPort": "3306"
}
]
},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"Mounts": [
{
"Type": "volume",
"Name": "mysql-data",
"Source": "/var/lib/docker/volumes/mysql-data/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "3aad772538b5",
...
"ExposedPorts": {
"3306/tcp": {}
},
...
"Env": [
"MYSQL_ROOT_PASSWORD=123456",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/mysql/bin:/usr/local/mysql/scripts",
"GOSU_VERSION=1.7",
"MYSQL_MAJOR=5.5",
"MYSQL_VERSION=5.5.62"
],
"Cmd": [
"--character-set-server=utf8"
],
1, 容器层:⽂件存放路径
#1, 启动容器
[root@master ~]# docker run -d --name nginx2 nginx
a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8
#2, 获取容器id
[root@master ~]# docker inspect nginx2 | grep -i id
[root@master ~]# docker inspect nginx2 | grep -i id
"Id": "a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8",
"Pid": 2069,
"ExecIDs": null,
"ContainerIDFile": "",
#查看容器临时⽂件--每次创建时随机⽣成的⽂件(容器层)
# /var/lib/docker/containers/容器id
[root@master ~]# docker inspect nginx2 | grep -i path
"Path": "nginx",
"ResolvConfPath": "/var/lib/docker/containers/af",
"HostnamePath": "/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8/hostname",
"HostsPath": "/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e5
4c8cf9e5ff24c8/hosts",
"LogPath": "/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8-json.log",后天修改容器端⼝
a, 先提交旧容器为新的镜像,再启动新容器
需要确保:数据卷映射完全⼀致(新旧的容器,在数据卷上要⼀致)
[root1@c7-docker ~]# docker inspect mysql_port |egrep -i 'volum|Mount' -A 2
"Volumes": {
"/var/lib/mysql": {}
},
--
"Volumes": {
"/var/lib/mysql": {}
},
保存容器为镜像,再启动新容器是,添加端⼝映射
>>#### 1, 启动⼀个容器 >>####
[root1@c7-docker ~]# docker run --name t1 -d -e MYSQL_ROOT_PASSWORD=123456 -v mysql-test-dir:/var/lib/mysql/ -p 3308:3306 mysql:5.5
53f2a3c53d4c6769897ee484c3d2ff4e3f82ea1e390d4950b2162c08af05d7cc
[root1@c7-docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53f2a3c53d4c mysql:5.5 "docker-entrypoint.s…" 3 seconds ago Up 3 seconds 0.0.0.0:3308->3306/tcp t1
[root1@c7-docker ~]# mysql -uroot -p123456 -P3308 --protocol tcp
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.62 MySQL Community Server (GPL)
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MySQL [(none)]> create database test;
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> use test;
Database changed
MySQL [test]> create table t1(id int);
Query OK, 0 rows affected (0.00 sec)
MySQL [test]> insert into t1 values(1),(2),(3);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
MySQL [test]> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
>>#### 2, 提交当前容器环境--保存为新的镜像 >>####
[root1@c7-docker ~]# docker commit -m mysql_test_chag-port_img t1 mysql_port
sha256:9f90be3c200c6a8b535478375c4caf86d589d231afae1293d28026f9248f8ae3
[root1@c7-docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql_port latest 9f90be3c200c 3 seconds ago 205MB
mysql 5.5 d404d78aa797 18 months ago 205MB
>>#### 3, 停⽌旧容器, 启动新容器 >>####
[root1@c7-docker ~]# docker stop t1
t1
[root1@c7-docker ~]# docker run --name t2 -d -v mysql-test-dir:/var/lib/mysql/ -p 3309:3306 mysql_port
fd7cefe55db8bb2687ab044ff1473f0c935ac5ce867df81b3b13f570e9026868
[root1@c7-docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd7cefe55db8 mysql_port "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:3309->3306/tcp t2
[root1@c7-docker ~]# mysql -uroot -p123456 -P3309 --protocol tcp
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.62 MySQL Community Server (GPL)
MySQL [(none)]> show databases;
MySQL [(none)]> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [test]> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
b, 修改容器配置⽂件置⽂件:hostconfig.json
要先停⽌docker服务,否则不⽣效
通过容器层⽂件,到配置⽂件hostconfig.json,修改容器映射的端⼝
[root@ff24c8]# pwd
/var/lib/docker/2e544ccfa
[root@ff24c8]# cat hostconfig.json
{"Binds":["/dockersuperset:/home/superset"],"ContainerIDFile":"",
"LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default",
"PortBindings":{"8088/tcp":[{"HostIp":"","HostPort":"8099"}]}......
2, 镜像层:⽂件存放路径
[root@master ~]# docker image inspect nginx |tail -n 22
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/bf20cf788cc053f00ff1467525d50e19bd1cf07a2167f72511bdfcb
28918a472/diff:/var/lib/docker/overlay2/317d80bb7ae58ed288be9ebd84aeb5b4b3a1c06f3211f5d1f32d89b629d1876e/diff", "MergedDir": "/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/merged",
"UpperDir": "/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/diff",
"WorkDir": "/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/work"
},
"Name": "overlay2"
},
a, 容器层,镜像层:关联
I, ⼦容器:拷贝镜像的⽂件
II, ⼦容器:添加新⽂件
III, ⼦容器:修改由镜像拷贝的⽂件
b, 在镜像层(⽂件存储⽬录),修改配置⽂件
# 进⼊镜容器⽂件存储⽬录,修改配置⽂件
[root@0c0599b]# ls diff/run/
nginx.pid
[root@0c0599b]# ls diff/var/cache/nginx/
client_temp fastcgi_temp proxy_temp scgi_temp uwsgi_temp
[root@0c0599b]# ls merged/
bin/ dev/ etc/ lib/ media/ opt/ root/ sbin/ sys/ usr/
boot/ .dockerenv home/ lib64/ mnt/ proc/ run/ srv/ tmp/ var/
[root@0c0599b]# ls merged/etc/nginx/
conf.d fastcgi_params koi-utf pes f scgi_params uwsgi_params win-utf
[root@0c0599b]# head merged/etc/f
user nginx;
worker_processes 1;
#在此处修改配置⽂件,把user nginx; worker_process 1; 这两⾏的分号去掉,看容器⾥⾯的配置是否更改
[root@0c0599b]# head merged/etc/f -n 3
user nginx
worker_processes 1
#登陆容器,查看修改的配置:验证是否⽣效
[root@0c0599b]# docker exec -it nginx2 bash
root@a9c9f31cdccf:/# head /etc/f -n 3
user nginx
worker_processes 1
3, 修改默认存储路径
a, 重建/var/lib/docker⽬录
#备份数据到新的存放路径
service docker stop
mkdir /docker.bak
mv /var/lib/docker/* /docker.bak
#创建软连接
mkdir /home/docker-data
mv /docker.bak/* /home/docker-data/ && rmdir /docker.bak
ln -s /home/docker-data /var/lib/docker
b, 修改配置
vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --graph /new-path/docker
#reload配置⽂件
systemctl daemon-reload
#重启docker
systemctl restart docker.service
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。如有错误或未考虑完全的地⽅,望不吝赐教。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
推荐文章
热门文章
-
随机森林算法的改进方法
2024-10-02 -
基于随机森林算法的风险预警模型研究
2024-10-02 -
Python中的随机森林算法详解
2024-10-02 -
随机森林发展历史
2024-10-02 -
如何使用随机森林进行时间序列数据模式识别(八)
2024-10-02 -
随机森林回归模型原理
2024-10-02 -
如何使用随机森林进行时间序列数据模式识别(六)
2024-10-02 -
如何使用随机森林进行时间序列数据预测(四)
2024-10-02 -
如何使用随机森林进行异常检测(六)
2024-10-02 -
随机森林算法和grandientboosting算法 -回复
2024-10-02 -
随机森林方法总结全面
2024-10-02 -
随机森林算法原理和步骤
2024-10-02 -
随机森林的原理
2024-10-02 -
随机森林 重要性
2024-10-02 -
随机森林算法
2024-10-02 -
机器学习中随机森林的原理
2024-10-02 -
随机森林算法原理
2024-10-02 -
使用计算机视觉技术进行动物识别的技巧
2024-10-02 -
基于crf命名实体识别实验总结
2024-10-02 -
transformer预测模型训练方法
2024-10-02
最新文章
-
随机森林算法介绍及R语言实现
2024-10-02 -
基于随机森林优化的神经网络算法在冬小麦产量预测中的应用研究_百度文 ...
2024-10-02 -
基于正则化贪心森林算法的情感分析方法研究
2024-10-02 -
随机森林算法和grandientboosting算法
2024-10-02 -
基于随机森林的图像分类算法研究
2024-10-02 -
随机森林结合直接正交信号校正的模型传递方法
2024-10-02
发表评论