DEV Community

Cover image for How to open/edit/bind ports to running Docker Containers
Joseph Peculiar
Joseph Peculiar

Posted on

How to open/edit/bind ports to running Docker Containers

You have a running production container (a synced node) and you would want to either edit or bind new ports in this container, as opposed to spinning up a new container.

The following steps should aid you to achieve this.

1.Stop the running Container

docker stop <container-id>

2.Open Docker containers directory

cd /var/lib/docker/containers/

cd <container-id>

Alt Text

3.Edit hostconfig.json

Open hostconfig.json with nano or vim
locate and edit PortBindings with the new ports you want to edit, open or delete.

for instance

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

4.Restart Docker

systemctl restart docker

5.Start container

docker start <container-id>

Top comments (2)

Collapse
 
viktorpredictor profile image
ViktorPredictor

Yo bro how can i return my hostconfig.json back how it was ? i absolutly fucked up something i change the ports numbers but then i didnt know how to save it I started pressing random keys and now its all broken I tried to get it back how it was but seems like i created 17 hostcling swp files ( idk what that means ) and when i try to recover them I press 17 to recover the latest one and press enter and nothing happens so i really need some help right now
´

Image description
Image description

Collapse
 
hawktian profile image
Hawk Tian

Thank you.