docker启动一个容器后,想更换映射端口,或者添加新的端口,如果不想重启一个新的容器,可以尝试在原有容器配置中修改关于端口映射的信息,步骤如下:

1. docker stop [container_id]

2. systemctl stop docker 

3. 修改hostconfig.json和config.v2.json文件中HostPort的端口号,这两个文件都在下面的路径中:/var/lib/docker/containers/[hash_of_the_container]/,其中hash_of_the_container可以通过命令: docker inspect [container_id] |grep Id 获得。

4. systemctl start docker

5. docker start [container_id]

比如,我要修改原来映射到80的端口,变成81端口, hostconfig.json和config.v2.json对应修改如下

docker修改容器映射port

docker修改容器映射port

 

相关文章:

  • 2020-11-17
  • 2022-12-23
  • 2021-06-16
  • 2021-01-24
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2021-11-24
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案