Updating Port Mappings for Docker Containers Using “docker commit”

Applies to…

  • DxOdyssey 19.5 and newer

Summary

Docker does not allow container port mappings to be modified after launch. By using Docker’s commit command, ports can be mapped to an new container with little downtime. These steps are required when additional port mappings are needed for containers running DxOdyssey and the /etc/dh2i folder is not mounted to a volume.

Information

A tunnel origin, whether a single gateway or multiple gateways (.ACTIVE, .PART, etc.), must have a listener on the gateway to function. In Docker, the listening port must be mapped when the container is launched. If the container does not have the correct mapping, the origin will be inoperative on that gateway. A port cannot be mapped to an existing container, but that container can be “committed” and used as the base image for a new container with updated port mappings. Do the following:

  1. Gather information for the container.
    1. Execute “docker container ls” on the host machine for the container. This command will list information about all running containers on the machine. Alternatively, executing “docker port < CONTAINER_NAME >” will list port mappings for a specific container. For both commands, the numbers on the left will be the existing mapped ports on the host machine and the number on the right are the corresponding listening ports within the container(s). Note which container ports are already mapped, as these configurations are needed to keep existing origins functional.
    2. Execute “docker exec < CONTAINER_NAME > hostname” to get the hostname of the container.
  2. Create a new container with the updated port mappings.
    1. Execute “docker stop < CONTAINER_NAME >” to stop the container.
    2. Execute “docker commit < CONTAINER_NAME > < NEW_IMAGE_NAME >” using the current container and a new image name to create a new image based on the container.
    3. Execute “docker container rm < CONTAINER_NAME >” to remove the old container.
    4. Execute “docker run” with the previously configured port mappings for the container, the new port mapping, a new /etc/dh2i volume, the same host name, and the newly committed image. The -p flag is for each mapped port, -d runs the container detached so the host machine’s command line is usable after the container is run, and -h specifies the host name used by the container. For example:
      docker run -p 57979:7979 -p 51433:1433 -v dxoVolume:/etc/dh2i -d -h < HOST_NAME > < NEW_IMAGE_NAME >
      NOTE: DH2i recommends using volume mounts to store DxOdyssey’s configuration information. See this KB article for information about adding volumes.
  • The DxOdyssey container will automatically rejoin the gateway group. After joining, the user can configure tunnels that will utilize the updated port mappings.

Additional information