运行容器添加映射端口或目录

参考:https://www.jianshu.com/p/8052fa5b1933
1)首先,docker ps -a 获取要修改容器的id;
2)再进 cd /var/lib/docker/containers/{ids}
docker info | grep Root 获取以上位置;
3)备份文件
cp hostconfig.json => hostconfig.json.template
config.v2.json => config.v2.json.template
4)进入容器文件夹下
systemctl stop docker ,这个要先执行;
把内容拷贝到文本文件工具,编辑;
删除重建 hostconfig.json 或 config.v2.json ,将编辑后内容拷贝进来;
再 systemctl start docker
docker start 容器id;
==================================

2、修改 config.v2.json

添加宿主机/home/nginx映射到容器的/import
找到MountPoints,添加以下文字,如果省略有内容,注意加逗号

“MountPoints”: {
  .....省略  注意逗号
  "/import": {"Source": "/home/nginx","Destination": "/import","RW": true,"Name": "","Driver": "","Type":   "bind","Propagation": "rprivate","Spec": {"Type": "bind","Source":"/home/nginx","Target":   "/import"},"SkipMountpointCreation": false}
}

3、修改 hostconfig.json,添加以下红色文字
添加”Binds”:[“/home/nginx:/import”]
/////////////////修改端口/////////////////////////////////////////////////////////////////////
参考:https://zhuanlan.zhihu.com/p/565026121

1. hostconfig.json修改 (两处)
"ExposedPorts":{"50070/tcp":{},"8080/tcp":{}}
"Ports":{"50070/tcp":[{"HostIp":"0.0.0.0","HostPort":"50070"}],"8080/tcp":[{"HostIp":"0.0.0.0","HostPort":"7011"}]}
2. config.v2.json
"PortBindings":{"50070/tcp":[{"HostIp":"","HostPort":"50070"}],"8080/tcp":[{"HostIp":"","HostPort":"7011"}]}
欢迎您的到来,感谢您的支持!

为您推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注