修改docker镜像的映射端口号
先查看已存在的镜像的container id
[root@192 mysql_geek]# docker ps container id image command created status ports names 841d16cc9175 mysql:5.7.29 "docker-entrypoint.s…" 23 hours ago up 23 hours 0.0.0.0:3306->3306/tcp, 33060/tcp mysql_geek
去 /var/lib/docker/containers/ 目录下
修改对应镜像的配置。
(镜像配置以 container id 作为文件夹名)。
hostconfig.json
eg. 将 3306 改为 3307
"networkmode": "default",
"portbindings": {
"3306/tcp": [
{
"hostip": "",
"hostport": "3307"
}
]
},
{
"binds": null,
"containeridfile": "",
"logconfig": {
"type": "json-file",
"config": {}
},
"networkmode": "default",
"portbindings": {
"3306/tcp": [
{
"hostip": "",
"hostport": "3307"
}
]
},
"restartpolicy": {
"name": "no",
"maximumretrycount": 0
},
"autoremove": false,
"volumedriver": "",
"volumesfrom": null,
"capadd": null,
"capdrop": null,
"capabilities": null,
"dns": [],
"dnsoptions": [],
"dnssearch": [],
"extrahosts": null,
"groupadd": null,
"ipcmode": "private",
"cgroup": "",
"links": null,
"oomscoreadj": 0,
"pidmode": "",
"privileged": false,
"publishallports": false,
"readonlyrootfs": false,
"securityopt": null,
"utsmode": "",
"usernsmode": "",
"shmsize": 67108864,
"runtime": "runc",
"consolesize": [
0,
0
],
"isolation": "",
"cpushares": 0,
"memory": 0,
"nanocpus": 0,
"cgroupparent": "",
"blkioweight": 0,
"blkioweightdevice": [],
"blkiodevicereadbps": null,
"blkiodevicewritebps": null,
"blkiodevicereadiops": null,
"blkiodevicewriteiops": null,
"cpuperiod": 0,
"cpuquota": 0,
"cpurealtimeperiod": 0,
"cpurealtimeruntime": 0,
"cpusetcpus": "",
"cpusetmems": "",
"devices": [],
"devicecgrouprules": null,
"devicerequests": null,
"kernelmemory": 0,
"kernelmemorytcp": 0,
"memoryreservation": 0,
"memoryswap": 0,
"memoryswappiness": null,
"oomkilldisable": false,
"pidslimit": null,
"ulimits": null,
"cpucount": 0,
"cpupercent": 0,
"iomaximumiops": 0,
"iomaximumbandwidth": 0,
"maskedpaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"readonlypaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
}
hostconfig.json
{
"binds": null,
"containeridfile": "",
"logconfig": {
"type": "json-file",
"config": {}
},
"networkmode": "default",
"portbindings": {
"3306/tcp": [
{
"hostip": "",
"hostport": "3307"
}
]
},
"restartpolicy": {
"name": "no",
"maximumretrycount": 0
},
"autoremove": false,
"volumedriver": "",
"volumesfrom": null,
"capadd": null,
"capdrop": null,
"capabilities": null,
"dns": [],
"dnsoptions": [],
"dnssearch": [],
"extrahosts": null,
"groupadd": null,
"ipcmode": "private",
"cgroup": "",
"links": null,
"oomscoreadj": 0,
"pidmode": "",
"privileged": false,
"publishallports": false,
"readonlyrootfs": false,
"securityopt": null,
"utsmode": "",
"usernsmode": "",
"shmsize": 67108864,
"runtime": "runc",
"consolesize": [
0,
0
],
"isolation": "",
"cpushares": 0,
"memory": 0,
"nanocpus": 0,
"cgroupparent": "",
"blkioweight": 0,
"blkioweightdevice": [],
"blkiodevicereadbps": null,
"blkiodevicewritebps": null,
"blkiodevicereadiops": null,
"blkiodevicewriteiops": null,
"cpuperiod": 0,
"cpuquota": 0,
"cpurealtimeperiod": 0,
"cpurealtimeruntime": 0,
"cpusetcpus": "",
"cpusetmems": "",
"devices": [],
"devicecgrouprules": null,
"devicerequests": null,
"kernelmemory": 0,
"kernelmemorytcp": 0,
"memoryreservation": 0,
"memoryswap": 0,
"memoryswappiness": null,
"oomkilldisable": false,
"pidslimit": null,
"ulimits": null,
"cpucount": 0,
"cpupercent": 0,
"iomaximumiops": 0,
"iomaximumbandwidth": 0,
"maskedpaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"readonlypaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
}
重启 docker
systemctl restart docker
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论