docker api url调用

本文介绍了在Docker安装后如何开启API的远程访问功能,包括修改service文件以添加启动参数,并提供了重启服务及验证API访问的方法。

docker安装后没有开启API 远程访问

如有需要则需要修改启动参数

因为使用systemctl进行启动docker服务, 因此修改对应的service文件

具体方法:

修改文件:/usr/lib/systemd/system/docker.service中的ExecStart

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock  -H tcp://0.0.0.0:4312

添加 -H tcp://0.0.0.0:4312

重启服务:

[root@docker2 ~]# systemctl daemon-reload 
[root@docker2 ~]# 
[root@docker2 ~]# systemctl restart docker
[root@docker2 ~]# 
[root@docker2 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-08-11 04:46:11 EDT; 8s ago
     Docs: https://docs.docker.com
 Main PID: 4764 (dockerd)
   Memory: 44.1M
   

[root@docker2 ~]# netstat -antp | grep 4312
tcp6       0      0 :::4312                 :::*                    LISTEN      4764/dockerd        
[root@docker2 ~]# 

访问服务:

 curl http://localhost:4312/info

获取到json信息:

{
    "ID":"32HU:3HW4:T3QL:J2OG:NER2:BO3P:3RE4:F4IQ:TJAD:IQNO:2JHO:RQ5Z",
    "Containers":3,
    "ContainersRunning":0,
    "ContainersPaused":0,
    "ContainersStopped":3,
    "Images":5,
    "Driver":"devicemapper",
    "DriverStatus":[
        [
            "Pool Name",
            "docker-253:1-69296955-pool"
        ],
        [
            "Pool Blocksize",
            "65.54kB"
        ],
        [
            "Base Device Size",
            "10.74GB"
        ],
        [
            "Backing Filesystem",
            "xfs"
        ],
        [
            "Udev Sync Supported",
            "true"
        ],
        [
            "Data file",
            "/dev/loop0"
        ],
        [
            "Metadata file",
            "/dev/loop1"
        ],
        [
            "Data loop file",
            "/var/lib/docker/devicemapper/devicemapper/data"
        ],
        [
            "Metadata loop file",
            "/var/lib/docker/devicemapper/devicemapper/metadata"
        ],
        [
            "Data Space Used",
            "996.9MB"
        ],
        [
            "Data Space Total",
            "107.4GB"
        ],
        [
            "Data Space Available",
            "14.85GB"
        ],
        [
            "Metadata Space Used",
            "1.802MB"
        ],
        [
            "Metadata Space Total",
            "2.147GB"
        ],
        [
            "Metadata Space Available",
            "2.146GB"
        ],
        [
            "Thin Pool Minimum Free Space",
            "10.74GB"
        ],
        [
            "Deferred Removal Enabled",
            "true"
        ],
        [
            "Deferred Deletion Enabled",
            "true"
        ],
        [
            "Deferred Deleted Device Count",
            "0"
        ],
        [
            "Library Version",
            "1.02.149-RHEL7 (2018-07-20)"
        ]
    ],
    "SystemStatus":null,
    "Plugins":{
        "Volume":[
            "local"
        ],
        "Network":[
            "bridge",
            "host",
            "ipvlan",
            "macvlan",
            "null",
            "overlay"
        ],
        "Authorization":null,
        "Log":[
            "awslogs",
            "fluentd",
            "gcplogs",
            "gelf",
            "journald",
            "json-file",
            "local",
            "logentries",
            "splunk",
            "syslog"
        ]
    },
    "MemoryLimit":true,
    "SwapLimit":true,
    "KernelMemory":true,
    "KernelMemoryTCP":true,
    "CpuCfsPeriod":true,
    "CpuCfsQuota":true,
    "CPUShares":true,
    "CPUSet":true,
    "PidsLimit":false,
    "IPv4Forwarding":true,
    "BridgeNfIptables":true,
    "BridgeNfIp6tables":false,
    "Debug":false,
    "NFd":24,
    "OomKillDisable":true,
    "NGoroutines":36,
    "SystemTime":"2019-08-11T04:50:39.514826247-04:00",
    "LoggingDriver":"json-file",
    "CgroupDriver":"cgroupfs",
    "NEventsListener":0,
    "KernelVersion":"3.10.0-123.el7.x86_64",
    "OperatingSystem":"CentOS Linux 7 (Core)",
    "OSType":"linux",
    "Architecture":"x86_64",
    "IndexServerAddress":"https://index.docker.io/v1/",
    "RegistryConfig":{
        "AllowNondistributableArtifactsCIDRs":[

        ],
        "AllowNondistributableArtifactsHostnames":[

        ],
        "InsecureRegistryCIDRs":[
            "127.0.0.0/8"
        ],
        "IndexConfigs":{
            "docker.io":{
                "Name":"docker.io",
                "Mirrors":[
                    "http://hub-mirror.c.163.com/"
                ],
                "Secure":true,
                "Official":true
            }
        },
        "Mirrors":[
            "http://hub-mirror.c.163.com/"
        ]
    },
    "NCPU":2,
    "MemTotal":3961901056,
    "GenericResources":null,
    "DockerRootDir":"/var/lib/docker",
    "HttpProxy":"",
    "HttpsProxy":"",
    "NoProxy":"",
    "Name":"docker2",
    "Labels":[

    ],
    "ExperimentalBuild":false,
    "ServerVersion":"19.03.1",
    "ClusterStore":"",
    "ClusterAdvertise":"",
    "Runtimes":{
        "runc":{
            "path":"runc"
        }
    },
    "DefaultRuntime":"runc",
    "Swarm":{
        "NodeID":"",
        "NodeAddr":"",
        "LocalNodeState":"inactive",
        "ControlAvailable":false,
        "Error":"",
        "RemoteManagers":null
    },
    "LiveRestoreEnabled":false,
    "Isolation":"",
    "InitBinary":"docker-init",
    "ContainerdCommit":{
        "ID":"894b81a4b802e4eb2a91d1ce216b8817763c29fb",
        "Expected":"894b81a4b802e4eb2a91d1ce216b8817763c29fb"
    },
    "RuncCommit":{
        "ID":"425e105d5a03fabd737a126ad93d62a9eeede87f",
        "Expected":"425e105d5a03fabd737a126ad93d62a9eeede87f"
    },
    "InitCommit":{
        "ID":"fec3683",
        "Expected":"fec3683"
    },
    "SecurityOptions":[
        "name=seccomp,profile=default"
    ],
    "Warnings":[
        "WARNING: API is accessible on http://0.0.0.0:4312 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface",
        "WARNING: bridge-nf-call-ip6tables is disabled",
        "WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.",
        "WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
Use `--storage-opt dm.thinpooldev` to specify a custom block storage device."
    ]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值