Remove port binding from an existing docker container

Joyce Babu

Currently I have a container created with

docker run --detach --name gitlab_app --restart=always --publish 192.168.0.200:80:80 --publish 192.168.0.200:22:22 --volumes-from gitlab_data gitlab_image

I want to remove both port bindings 80 and 22 from the image. Is it possible to remove port binding from an existing docker container?

NB: It is okay to take the container offline for removing the binding.

Usman Ismail

If its ok for the container to be offline why not just remove and run again without the port switches?

If you do need to do this without deleting containers you could just modify the underlying iptables changes.

# Will list the rules
iptables -L

# Will delete the rule you want to remove
iptables --delete [chain] <Rule definition>

In general your data should always be in one of 3 places

  1. A data only container that can be linked with a restarted service container.
  2. A volume defined in your service container than can be linked with a new container to take backups. See here for an example.
  3. In a host mounted volume so that you can restart containers and mount the same location into new containers.

With one of these three approaches restarting services becomes easily and this should be standard as micro-services should be designed such that they can go down and recover often. These approaches will also speed up your application as the default union file system is slower than normal file systems which are used for volumes.

If you need to recover data from a container where you did not plan volumes properly you can use the docker export functionality to export the state of your container. Then import it into a new container with a host mounted volume. Copy your critical data from inside the container to the volume.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to access host port from docker container

From Java

How do I assign a port mapping to an existing Docker container?

From Java

Exposing a port on a live Docker container

From Java

Forward host port to docker container

From Java

"docker cp" all files from a folder to existing container folder

From Java

Change container port in docker compose

From Dev

Exposing a Docker container port

From Dev

How to configure a Docker container to be reachable by container_ip:port from outside the host machine?

From Dev

How to port forward in Docker container?

From Dev

How to get the mapped port on host from a docker container?

From Dev

How to expose port from host to container in Docker?

From Dev

Is there a way to remove a name from a Docker container?

From Dev

Port based routing in docker container

From Dev

Docker volumes binding: container to host

From Dev

Amazon AWS ECS Docker Port not binding correctly

From Dev

How to remove a mount for existing container?

From Dev

Port data out of docker container

From Dev

Docker port binding doesn't seem to work

From Dev

docker network port binding

From Dev

Docker EC2 & port binding

From Dev

Docker remove container error

From Dev

Error accessing host port from docker container on ubuntu

From Dev

docker container port accessed from another container

From Dev

docker container port format does not looks right(like <port>-<port>)

From Dev

Docker container with published port not accessible from outside

From Dev

docker service create container existing

From Dev

Connect from docker container to a host port

From Dev

Docker - connecting to an open port in a container

From Dev

Bind docker container port to path

Related Related

HotTag

Archive