Updating Port Mappings for Docker Containers Using “docker commit”
Summary
Docker does not allow container port mappings to be modified after launch. By using Docker's commit command, ports can be mapped to a 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:
-
Gather information for the container.
-
Execute
docker container ls
on the host machine for the container. This command will list information about all running containers on the machine. Alternatively, executingdocker 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. -
Execute
docker exec <CONTAINER_NAME> hostname
to get the hostname of the container.
-
-
Create a new container with the updated port mappings.
-
Execute
docker stop <CONTAINER_NAME>
to stop the container. -
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. -
Execute
docker container rm <CONTAINER_NAME>
to remove the old container. -
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>
infoDH2i recommends using volume mounts to store DxOdyssey's configuration information. See Creating a DxOdyssey Docker Container 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
- Using DxConnect with Linux DxOdyssey Installations
- Creating a DxOdyssey Docker Container
- Updating Port Mappings for DxOdyssey Docker Containers
- How to Setup a Docker Container as a Tunnel Origin without using DxConnect
- Adding a Tunnel Origin to a Docker Container
- Command Line Deployments of DxOdyssey