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

codaelux

Joseph Peculiar

Posted on November 5, 2020

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> 

Enter fullscreen mode Exit fullscreen mode

2.Open Docker containers directory


 /var/lib/docker/containers/ 

Enter fullscreen mode Exit fullscreen mode

 cd <container-id> 

Enter fullscreen mode Exit fullscreen mode

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"}]} 

Enter fullscreen mode Exit fullscreen mode

4.Restart Docker


 systemctl restart docker 

Enter fullscreen mode Exit fullscreen mode

5.Start container


 docker start <container-id> 

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
codaelux
Joseph Peculiar

Posted on November 5, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related