当前位置: 代码网 > 服务器>服务器>云虚拟主机 > 如何修改Docker镜像的映射端口号

如何修改Docker镜像的映射端口号

2024年05月14日 云虚拟主机 我要评论
修改docker镜像的映射端口号先查看已存在的镜像的container id[root@192 mysql_geek]# docker pscontainer id image

修改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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com