When you need to publish some port on a container that was already run, you can do this by changing internal docker files.
First, you need to find the container id
with
docker inspect <container_name>
Stop the container if it's running and go to the container directory:
cd /var/lib/docker/containers/<container_id>
For wsl
users, the container directory can be found here:\\wsl$\docker-desktop-data\version-pack-data\community\docker\containers
add "ExposedPorts"
to config.v2.json
:
"Config": {
....
"ExposedPorts": {
"<port_number>/tcp": {},
},
....
},
and "PortBindings"
to hostconfig.json
:
"PortBindings": {
"<port_number>/tcp": [
{
"HostIp": "",
"HostPort": "<port_number>"
}
]
}
For best results restart docker service:
systemctl restart docker
Now you can start the container and it should have ports published.
Top comments (0)