修改已存在的Docker容器的端口映射
测试环境:CentOS 7.9
Steps
停止当前容器。作为示例,wp是我要修改端口映射的容器名称。
1
$ docker container stop wp
停止Docker服务
1
$ systemctl stop docker
找到容器的HASH ID
1
2
3
4
5
6
7
8
9
10$ docker inspect wp
[root@l2m2 ~]# docker inspect wp
[
{
"Id": "547ecaa980a4be72120176fddc580c4fd3526a3c08831e016f996c01be36d846",
"Created": "2022-12-06T06:49:30.380291936Z",
"Path": "docker-entrypoint.sh",
"Args": [
"apache2-foreground"
],HASH ID为547ecaa980a4be72120176fddc580c4fd3526a3c08831e016f996c01be36d846
修改文件 /var/lib/docker/containers/[hash_of_the_container]/hostconfig.json
找到PortBindings,修改映射端口。
重启Docker服务
1
$ systemctl restart docker
启动容器
1
$ docker start wp