docker 修改现有镜像增加端口,增加调整卷映射

简书出现了致命问题,我2台电脑都无法上传图片,所以。。

查看容器信息:
(在openwrt中无需操作,直接点开容器就能看到id)
docker ps -a
查看容器的端口映射情况
docker port 容器ID或者容器名称
docker inspect 容器Id | grep Id
cd /etc/docker/containers
就可以看到一系列以文件id命名的文件夹

打开文件夹

root@OpenWrt:/mnt/sdc2/docker/containers/4aefd90041be2cf2fda5b1d17b50441c4962857938a8a33c0e23be75cb27ebf4# ls -l
-rw-r-----    1 root     root         37923 Sep  5 11:02 4aefd90041be2cf2fda5b1d17b50441c4962857938a8a33c0e23be75cb27ebf4-json.log
drwx------    2 root     root          4096 Sep  5 10:32 checkpoints
-rw-------    1 root     root          4932 Sep  5 11:15 config.v2.json
-rw-r--r--    1 root     root          2132 Sep  5 11:01 hostconfig.json
-rw-r--r--    1 root     root             6 Sep  5 10:32 hostname
-rw-r--r--    1 root     root           167 Sep  5 10:32 hosts
drwx--x---    2 root     root          4096 Sep  5 10:32 mounts
-rw-r--r--    1 root     root            50 Sep  5 10:32 resolv.conf
-rw-r--r--    1 root     root            71 Sep  5 10:32 resolv.conf.hash

需要修改的是config.v2.json和hostconfig.json
为了方便操作,使用MobaXterm连接终端,然后打开文件打开用vscode进行格式化json
【保存后自动上传】
config.v2.json
这里的Ports可能不需要改,似乎运行后自动会出现

"NetworkSettings": {
    },
        "Service": null,
        "Ports": {
            "22/tcp":  [{
                "HostIp": "0.0.0.0",
                "HostPort": "101"
            }, {
                "HostIp": "::",
                "HostPort": "101"
            }],
            "3000/tcp": [{
                "HostIp": "0.0.0.0",
                "HostPort": "100"
            }, {
                "HostIp": "::",
                "HostPort": "100"
            }]
        },

磁盘

"MountPoints": {
        "/data": {
            "Source": "",
            "Destination": "/data",
            "RW": true,
            "Name": "a3da5823e7537a297b37fd68d4e2a179acf3391893bc1e7ccd543841cd9482c4",
            "Driver": "local",
            "Type": "volume",
            "ID": "6002715d8d2b9ae05ddc5699dea6fbbcf2e469eaa193adf8bd20f4ed7503d657",
            "Spec": {},
            "SkipMountpointCreation": false
        }
    },

调整后

"MountPoints": {
        "/data": {
            "Source": "/mnt/sdc2/gitea/data",
            "Destination": "/data",
            "RW": true,
            "Name": "",
            "Driver": "",
            "Type": "bind",
            "Propagation": "rprivate",
            "Spec": {
                "Type": "bind",
                "Source": "/mnt/sdc2/gitea/data",
                "Target": "/data"
            },
            "SkipMountpointCreation": false
        }
    },

config.v2.json

image.png
image.png

附上我的完整文件

{
    "StreamConfig": {},
    "State": {
        "Running": false,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "RemovalInProgress": false,
        "Dead": false,
        "Pid": 0,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "0001-01-01T00:00:00Z",
        "FinishedAt": "0001-01-01T00:00:00Z",
        "Health": null
    },
    "ID": "60c28becb34bcb517f761b64a03e5b1432ade0702909f7dfea85985654abacc8",
    "Created": "2023-09-05T03:30:54.254130741Z",
    "Managed": false,
    "Path": "/usr/bin/entrypoint",
    "Args": ["/bin/s6-svscan", "/etc/s6"],
    "Config": {
        "Hostname": "aaaaaaa",
        "Domainname": "",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "ExposedPorts": {
            "22/tcp": {},
            "3000/tcp": {}
        },
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "USER=git", "GITEA_CUSTOM=/data/gitea"],
        "Cmd": ["/bin/s6-svscan", "/etc/s6"],
        "Image": "gitea/gitea:latest",
        "Volumes": {
            "/data": {}
        },
        "WorkingDir": "",
        "Entrypoint": ["/usr/bin/entrypoint"],
        "OnBuild": null,
        "Labels": {
            "maintainer": "maintainers@gitea.io",
            "org.opencontainers.image.created": "2023-08-20T19:34:31Z",
            "org.opencontainers.image.revision": "bcb0f3a90fae49047f73b37fcb50b075ed641dfa",
            "org.opencontainers.image.source": "https://github.com/go-gitea/gitea.git",
            "org.opencontainers.image.url": "https://github.com/go-gitea/gitea"
        }
    },
    "Image": "sha256:ac7e17ebe12d2607a14fee34e0a92b0216a1161cffd80cc35b862b25e899c801",
    "NetworkSettings": {
        "Bridge": "",
        "SandboxID": "",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Networks": {
            "bridge": {
                "IPAMConfig": null,
                "Links": null,
                "Aliases": null,
                "NetworkID": "",
                "EndpointID": "",
                "Gateway": "",
                "IPAddress": "",
                "IPPrefixLen": 0,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "",
                "DriverOpts": null,
                "IPAMOperational": false
            }
        },
        "Service": null,
        "Ports": null,
        "SandboxKey": "",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null,
        "IsAnonymousEndpoint": false,
        "HasSwarmEndpoint": false
    },
    "LogPath": "",
    "Name": "/aaaaaaa",
    "Driver": "overlay2",
    "OS": "linux",
    "MountLabel": "",
    "ProcessLabel": "",
    "RestartCount": 0,
    "HasBeenStartedBefore": false,
    "HasBeenManuallyStopped": false,
    "MountPoints": {
        "/data": {
            "Source": "/mnt/sdc2/gitea/data",
            "Destination": "/data",
            "RW": true,
            "Name": "",
            "Driver": "",
            "Type": "bind",
            "Propagation": "rprivate",
            "Spec": {
                "Type": "bind",
                "Source": "/mnt/sdc2/gitea/data",
                "Target": "/data"
            },
            "SkipMountpointCreation": false
        }
    },
    "SecretReferences": null,
    "ConfigReferences": null,
    "AppArmorProfile": "",
    "HostnamePath": "",
    "HostsPath": "",
    "ShmPath": "",
    "ResolvConfPath": "",
    "SeccompProfile": "",
    "NoNewPrivileges": false,
    "LocalLogCacheMeta": {
        "HaveNotifyEnabled": false
    }
}

hostconfig.json
卷调整为"Binds": ["/mnt/sdc2/gitea/data:/data"]多个用,
端口调整 "PortBindings": {

image.png
{
    "Binds": ["/mnt/sdc2/gitea/data:/data"],
    "ContainerIDFile": "",
    "LogConfig": {
        "Type": "json-file",
        "Config": {}
    },
    "NetworkMode": "bridge",
    "PortBindings": {
        "22/tcp": [{
            "HostIp": "",
            "HostPort": "103"
        }],
        "3000/tcp": [{
            "HostIp": "",
            "HostPort": "102"
        }]
    },
    "RestartPolicy": {
        "Name": "unless-stopped",
        "MaximumRetryCount": 0
    },
    "AutoRemove": false,
    "VolumeDriver": "",
    "VolumesFrom": null,
    "CapAdd": null,
    "CapDrop": null,
    "CgroupnsMode": "host",
    "Dns": null,
    "DnsOptions": null,
    "DnsSearch": null,
    "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": null,
    "BlkioDeviceReadBps": null,
    "BlkioDeviceWriteBps": null,
    "BlkioDeviceReadIOps": null,
    "BlkioDeviceWriteIOps": null,
    "CpuPeriod": 0,
    "CpuQuota": 0,
    "CpuRealtimePeriod": 0,
    "CpuRealtimeRuntime": 0,
    "CpusetCpus": "",
    "CpusetMems": "",
    "Devices": null,
    "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"]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值