docker

docker 修改 containers 容器 端口 HostPort

Docker 修改容器端口方法

主要分为以下几个操作:

  1. 停止docker服务
  2. 去修改容器端口
  3. 启动 docker服务。
  4. 启动 docker 容器
root@iZrj9211qpkykhu5s7bnb3Z:# systemctl stop  docker 这里先要停止docker,然后继续

root@iZrj9211qpkykhu5s7bnb3Z:~# docker ps 查看现有容器
CONTAINER ID   IMAGE       COMMAND                  CREATED      STATUS          PORTS                               NAMES
62ee52b19872   wordpress   "docker-entrypoint.s…"   3 days ago   Up 43 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   ibm_120
root@iZrj9211qpkykhu5s7bnb3Z:~# cd /var/lib/docker/containers/62ee52b19872*  进入容器目录
root@iZrj9211qpkykhu5s7bnb3Z:/var/lib/docker/containers/62ee52b198727d88a219277aa850e648ae7d3ef83b2c05bdef3a8e5669bb973f# vi hostconfig.json 编辑配置文件

然后看到如下内容:

{
    "Binds": ["/root/alibaba_ibm_120:/var/www/html"],
    "ContainerIDFile": "",
    "LogConfig": {
        "Type": "json-file",
        "Config": {}
    },
    "NetworkMode": "default",
    "PortBindings": {
        "80/tcp": [{
            "HostIp": "",
            "HostPort": "80"
        }]
    },
    "RestartPolicy": {
        "Name": "no",
        "MaximumRetryCount": 0
    },
    "AutoRemove": false,
    "VolumeDriver": "",
    "VolumesFrom": null,
    "CapAdd": null,
    "CapDrop": null,
    "CgroupnsMode": "host",
    "Dns": [],
    "DnsOptions": [],
    "DnsSearch": [],
    "ExtraHosts": null,
    "GroupAdd": null,
    "IpcMode": "private",
    "Cgroup": "",
    "Links": null,
    "OomScoreAdj": 0,
    "PidMode": "",
    "Privileged": false,
    "PublishAllPorts": false,
    "ReadonlyRootfs": false,
    "SecurityOpt": null,
    "UTSMode": "",
    "UsernsMode": "",
    "ShmSize": 67108864,
    "Runtime": "runc",
    "ConsoleSize": [0, 0],
    "Isolation": "",
    "CpuShares": 0,
    "Memory": 0,
    "NanoCpus": 0,
    "CgroupParent": "",
    "BlkioWeight": 0,
    "BlkioWeightDevice": [],
    "BlkioDeviceReadBps": null,
    "BlkioDeviceWriteBps": null,
    "BlkioDeviceReadIOps": null,
    "BlkioDeviceWriteIOps": null,
    "CpuPeriod": 0,
    "CpuQuota": 0,
    "CpuRealtimePeriod": 0,
    "CpuRealtimeRuntime": 0,
    "CpusetCpus": "",
    "CpusetMems": "",
    "Devices": [],
    "DeviceCgroupRules": null,
    "DeviceRequests": null,
    "KernelMemory": 0,
    "KernelMemoryTCP": 0,
    "MemoryReservation": 0,
    "MemorySwap": 0,
    "MemorySwappiness": null,
    "OomKillDisable": false,
    "PidsLimit": null,
    "Ulimits": null,
    "CpuCount": 0,
    "CpuPercent": 0,
    "IOMaximumIOps": 0,
    "IOMaximumBandwidth": 0,
    "MaskedPaths": ["/proc/asound", "/proc/acpi", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/proc/scsi", "/sys/firmware"],
    "ReadonlyPaths": ["/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"]
}

编辑:HostPort 的值,比如 改为:8080

执行如下命令重启 docker

systemctl start  docker

再执行如下命令 重启 docker 容器,这个时候,就已经把容器端口修改过来了。

docker start 62ee52b19872 后面跟上容器免

赛文市场营销

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注