Docker edit container parameter after

Have you ever created a container avec after some testing found out you forgot to do some port forwarding ?
Here is how to fix this without having to recreate the container:

  1. Get the container ID: docker ps -a

  2. Stop the container: docker stop [container name]

  3. Stop the docker: /etc/init.d/dockerd stop (or for generic linux: systemctl stop docker)

  4. Edit the container config.v2.json file, found at home/docker/containers/[container ID]/config.v2.json

  5. Within the ExposedPorts section, either edit the existing ports to the port you would like, or add them yourself. For example adding UDP port 1202:

"ExposedPorts":{"1880/tcp":{}},

      to

"ExposedPorts":{"1880/tcp":{},"1202/udp":{}},
  1. Within the Ports section, either edit the existing ports and HostPort to the port you would like, or add them yourself. For example adding UDP port 1202:
"Ports":{"1880/tcp":[{"HostIp":"0.0.0.0","HostPort":"1880"}]},

      to

"Ports":{"1880/tcp":[{"HostIp":"0.0.0.0","HostPort":"1880"}],"1202/udp":[{"HostIp":"0.0.0.0","HostPort":"1202"}]},
  1. Save and exit the config file

  2. Edit the container hostconfig.json file, found at home/docker/containers/[container ID]/hostconfig.json.

  3. Within the PortBindings section, either edit the existing ports and HostPort to the port you would like, or add them yourself. For example adding UDP port 1202:

"PortBindings":{"1880/tcp":[{"HostIp":"","HostPort":"1880"}]},

      to

"PortBindings":{"1880/tcp":[{"HostIp":"","HostPort":"1880"}],"1202/udp":[{"HostIp":"","HostPort":"1202"}]},
  1. Save and exit the config file

  2. Reboot the PLC

Original infomation:

2 Likes