从现有的码头收件箱中删除端口绑定 [英] Remove port binding from an existing docker container

查看:132
本文介绍了从现有的码头收件箱中删除端口绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个容器创建与

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

我想从图像中删除端口绑定 80 22 。是否可以从现有的码头收件箱中删除端口绑定?

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.

推荐答案

如果容器的离线状态为何不能在没有端口切换的情况下删除并再次运行?

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

如果您不需要删除容器你可以修改底层的iptables变化。

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>

一般来说,您的数据应始终位于3个位置之一

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


  1. 可以与重新启动的服务容器链接的仅数据容器。

  2. 您的服务容器中定义的卷可以与一个新的容器来备份。请参阅 here 作为示例。

  3. 在主机挂载的卷中,您可以重新启动容器并将相同的位置挂载到新的容器中。

  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.

如果您需要从未正确计划卷的容器中恢复数据,则可以使用docker导出功能导出容器的状态。然后将其导入具有主机挂载卷的新容器。将关键数据从容器中复制到卷。

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.

这篇关于从现有的码头收件箱中删除端口绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆