step 1: docker stop container_id
step 2: docker run -d -p 8000:8000 --name "abc" conainer_id
sudo docker ps sudo docker commit <containerid> <name/tag> sudo docker run -i -p 22 -p 8000:80 -m /data:/data -t <name/tag> /bin/bash
If your container already has SSH running and exposed, you can log into it interactively, reconfigure it to allow port forwarding and access your service through the port 22.
BTW, k8/openshift resolves this challenge by cloning a running container, additional ports can be exposed on the clone.
May I learn what type of container is involved here?
I appreciate all the answers but I still can't find the solution, I'm not working with Docker, I'm working with Podman, they are very similar but the solution presented to me through Docker does not work for me in podman.
I am working with docker.io/redhat/ubi8-init image...
I did not imagine that it would be so difficult to find a solution to this problem using PODMAN.
Revisiting one of the previous answers in detail I found a kind of solution, doing a commit:
$ docker stop httpd-container httpd-container $ docker commit httpd-container httpd-image sha256:33da33fcad051c90ac9b7dea9b2dbda442767e05ddebd8d6db8ac6893ef4ef40
Next, we’ll remove the container and start a fresh container using the image that we just created.
We need to make sure we add/update the port mappings in the run command this time:
$ docker rm httpd-container httpd-container $ docker run -d -p 83:80 --name httpd-container httpd-image dd2535c477ad74e80b3642abca9055efacb89eaf14572b91f91bf20cd3f0cbf3
This kind of solution works because the main point is not to lose all the setup that has already been made in the container.
If anyone knows of another type of solution that works with PODMAN too, I'd like to know...
I think your approach might be wrong but your question is valid and I can see you found an answer. You shold not be depending on that that is set up inside the container. If container is not stateless, you should persist data that needs to survive container re creation inside a volume. Container setup should be stored inside Dockerfile used to build it.
I saw one response that @Carey's comprehensive and well documented solution did not work for Podman.
If that is true, and the goal is truly to keep the container running, could this be accomplished by establishing an IPTABLES redirect, added to the same chain as the other Docker port redirects? (And then updating your documentation so that the next time you spin out a container, you've got the additional port or ports specified)
I've not tried this in the past, as I generally set persistent data and try to compose everything so that redeploying is at least nearly automated, but I've mused about whether it would be possible or not.
Podman does not support modifying port mapping of an existing container. The supported way is to re-create a container.
A workaround would be to modify the configuration of a container.
Podman 2.2 stores containers' configuration data in $HOME/.local/share/containers/storage/libpod/bolt_state.db for rootless containers. bolt_state.db is an embedded key/value database for Go (https://github.com/boltdb/bolt). You may manipulate it directly with the API or with boltbrowser, a CLI Browser for BoltDB Files (https://github.com/br0xen/boltbrowser)
To install the tool use:
$ sudo dnf install -y golang
$ sudo dnf install -y git
$ go get github.com/br0xen/boltbrowser
Eventually the tool will be installed in <working_dir>/go/bin/boltbrowser
Now you can browse/manipulate the bolt_state.db file:
A BoltDB file consists of buckets, and buckets are collections of key/value pairs within the database.
You need to modify the value of key:
ctr -> <container_hash> -> config
The value is a JSON string, so you need carefully amend/insert the below snippet into the value:
Adjust the number of ports as required.
Verify the settings with:
$ podman inspect <container_name>
To identify the container hash use:
$ podman inspect <container_name> | grep Id
Note. Before manipulating the config database, ensure all the containers are stopped.
# podman port -a (or use the container ID)
A collaborative learning environment, enabling open source skill development.