1、查看正在运行的容器:
1 2 3 |
root@ze6jxioZ:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0e2fe67bccee jumpserver/jms_all:latest "entrypoint.sh" 3 hours ago Up 5 seconds 0.0.0.0:18888->80/tcp, 0.0.0.0:12222->2222/tcp jms_all |
如果容器已经停止可以使用:
1 2 3 |
root@ze6jxioZ:~# docker container list -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0e2fe67bccee jumpserver/jms_all:latest "entrypoint.sh" 3 hours ago Exited (137) 2 minutes ago jms_all |
2、查看容器信息:
1 |
docker inspect 0e2fe67bccee |
能够看到其中的PortBindings。
3、将其停止:
1 2 |
root@ze6jxioZ:~# docker stop 0e2fe67bccee 0e2fe67bccee |
4、切换到位于/var/lib/docker/containers/下完整的id(hash)的文件夹:
1 2 3 4 5 6 7 8 |
root@ze6jxioZ:~# cd /var/lib/docker/containers/ root@ze6jxioZ:/var/lib/docker/containers# cd ~ root@ze6jxioZ:~# cd /var/lib/docker/containers/ root@ze6jxioZ:/var/lib/docker/containers# ls 0e2fe67bcceefab7ace2388b22836aadf954cdb206e44e071f474740412be45d root@ze6jxioZ:/var/lib/docker/containers# cd 0e2fe67bcceefab7ace2388b22836aadf954cdb206e44e071f474740412be45d/ root@ze6jxioZ:/var/lib/docker/containers/0e2fe67bcceefab7ace2388b22836aadf954cdb206e44e071f474740412be45d# ls 0e2fe67bcceefab7ace2388b22836aadf954cdb206e44e071f474740412be45d-json.log checkpoints config.v2.json hostconfig.json hostname hosts mounts resolv.conf resolv.conf.hash |
其中需要修改的是hostconfig.json,直接grep一下:
1 2 3 4 5 |
root@ze6jxioZ:/var/lib/docker/containers/0e2fe67bcceefab7ace2388b22836aadf954cdb206e44e071f474740412be45d# grep 18888 * grep: checkpoints: Is a directory hostconfig.json: ... {"PortBindings":{"2222/tcp":[{"HostIp":"","HostPort":"12222"}],"80/tcp":[{"HostIp":"","HostPort":"18888"}]} ... grep: mounts: Is a directory root@ze6jxioZ:/var/lib/docker/containers/0e2fe67bcceefab7ace2388b22836aadf954cdb206e44e071f474740412be45d# vim hostconfig.json |
修改完成后需要重启docker服务,然后再启动容器就可以了(不重启的话启动容器hostconfig.json又会被还原为之前的配置):
1 |
systemctl restart docker |
这个方法操作简单,缺点是需要重启整个docker服务,如果在同一个宿主机上运行着多个容器服务的话会影响其他容器服务。
转载时请保留出处,违法转载追究到底:进城务工人员小梅 » 修改已有Docker容器的端口映射