美文网首页
docker 修改现有镜像增加端口,增加调整卷映射

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

作者: 吉凶以情迁 | 来源:发表于2023-09-05 17:25 被阅读0次

简书出现了致命问题,我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"]
}

相关文章

  • Docker动态绑定宿主机端口

    查看宿主机绑定情况 增加一个端口映射,比如8081->81 修改端口绑定 删除规则编号

  • Docker的基本使用

    创建镜像 新建一个docker容器,并映射端口号。 查看本地的docker镜像 查看正在运行的docker容器。 ...

  • 在wordpress镜像中增加xdebug功能

    前言 修改官方的wordpress镜像,增加xdebug插件功能。 问题 docker环境中,官方的wordpre...

  • Docker搭建MySQL主从

    Docker安装mysql 首先拉取docker镜像 启动容器 Master对外映射的端口是3339,Slave对...

  • docker修改映射端口

    简述 docker容器在启动的时候,或者dockerfile构建的时候就定义好了映射到宿主机的端口。如果想要新增或...

  • SpringBoot制作docker镜像

    SpringBoot制作docker镜像 开启2375端口 修改docker配置文件 vim /usr/lib/s...

  • docker追加docker容器端口映射的方法

    docker run可以指定端口映射,但是容器一旦生成,就没有一个命令可以直接修改。通常间接的办法是,保存镜像,再...

  • 动态更新docker容器端口映射的方法

    docker run可以指定端口映射,但是容器一旦生成,就没有一个命令可以直接修改。通常间接的办法是,保存镜像,再...

  • docker

    docker镜像目录 导出镜像 写时复制 docker镜像服务 nginx反向代理增加安全性https://git...

  • Docker-端口映射

    Docker-端口映射 Docker端口映射 docker容器在启动的时候,如果不指定端口映射参数,在容器外部是无...

网友评论

      本文标题:docker 修改现有镜像增加端口,增加调整卷映射

      本文链接:https://www.haomeiwen.com/subject/yhzqvdtx.html