Docker配置文件在Ubuntu中不起作用的解决办法
2016-09-04 00:00
417 查看
环境
1. OS 版本: Ubuntu 16.04 LTS
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Release: 16.04 Codename: xenial
2. Docker版本: Docker version 1.11.2, build b9f10c9
$ docker -v Docker version 1.11.2, build b9f10c9
问题描述
最近想使用Docker的Remote API,即使用REST API的形式访问、操作Docker,按照网上的几篇文章配置,发现无法启用Docker的Remote API,于是便有此文。解决办法
1. 设置Docker开机启动(可选)
sudo systemctl enable docker
2. 配置Docker配置文件,Docker配置文件位于 /etc/default/docker ,配置文件如下:
# Customize location of Docker binary (especially for development testing). #DOCKER="/usr/local/bin/docker" # Use DOCKER_OPTS to modify the daemon startup options. #DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4" DOCKER_OPTS="-H=unix:///var/run/docker.sock -H=0.0.0.0:7654" # If you need Docker to use an HTTP proxy, it can also be specified here. #export http_proxy="http://127.0.0.1:3128/" # This is also a handy place to tweak where Docker's temporary files go. #export TMPDIR="/mnt/bigdrive/docker-tmp"
注意配置文件中的
DOCKER_OPTS="-H=unix:///var/run/docker.sock -H=0.0.0.0:7654"
红色部分即为配置启用Docker Remote API,访问端口为7654
3. 确定 docker.service 文件位置
$ systemctl show --property=FragmentPath docker FragmentPath=/lib/systemd/system/docker.service
如上,我机器上的docker.service文件位于 /lib/systemd/system/docker.service
4. 修改 docker.service 文件配置
首先查看 docker.service[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/docker daemon -H fd:// MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes
我们需要在 [Service] 部分中加入 EnvironmentFile 配置以及给 ExecStart 配置添加 $DOCKER_OPTS 参数,配置后的配置文件如下:
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] EnvironmentFile=-/etc/default/docker Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTS MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes
5. 重新加载配置文件
systemctl daemon-reload
6. 查看配置参数是否起作用
$ systemctl show docker | grep EnvironmentFile EnvironmentFile=/etc/default/docker (ignore_errors=yes)
7. 测试 Docker Remote API
curl localhost:7654/info | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1381 100 1381 0 0 196k 0 --:--:-- --:--:-- --:--:-- 224k { "ID": "AMPA:7NQC:J6QJ:SMNQ:CFOR:QA5V:NJY5:SJLP:NLFB:EJA7:KHIO:43TO", "Containers": 0, "ContainersRunning": 0, "ContainersPaused": 0, "ContainersStopped": 0, "Images": 7, "Driver": "aufs", "DriverStatus": [ [ "Root Dir", "/var/lib/docker/aufs" ], [ "Backing Filesystem", "extfs" ], [ "Dirs", "80" ], [ "Dirperm1 Supported", "true" ] ], "SystemStatus": null, "Plugins": { "Volume": [ "local" ], "Network": [ "bridge", "null", "host" ], "Authorization": null }, "MemoryLimit": true, "SwapLimit": false, "KernelMemory": true, "CpuCfsPeriod": true, "CpuCfsQuota": true, "CPUShares": true, "CPUSet": true, "IPv4Forwarding": true, "BridgeNfIptables": true, "BridgeNfIp6tables": true, "Debug": false, "NFd": 14, "OomKillDisable": true, "NGoroutines": 33, "SystemTime": "2016-09-04T21:24:40.951697312+08:00", "ExecutionDriver": "", "LoggingDriver": "json-file", "CgroupDriver": "cgroupfs", "NEventsListener": 0, "KernelVersion": "4.4.0-28-generic", "OperatingSystem": "Ubuntu 16.04 LTS", "OSType": "linux", "Architecture": "x86_64", "IndexServerAddress": "https://index.docker.io/v1/", "RegistryConfig": { "InsecureRegistryCIDRs": [ "127.0.0.0/8" ], "IndexConfigs": { "docker.io": { "Name": "docker.io", "Mirrors": null, "Secure": true, "Official": true } }, "Mirrors": null }, "NCPU": 4, "MemTotal": 4125618176, "DockerRootDir": "/var/lib/docker", "HttpProxy": "", "HttpsProxy": "", "NoProxy": "", "Name": "poet-pc", "Labels": null, "ExperimentalBuild": false, "ServerVersion": "1.11.2", "ClusterStore": "", "ClusterAdvertise": "" }
-----------------------------------------------------------------------------------
官方文档链接: https://docs.docker.com/engine/admin/systemd/
相关文章推荐
- ubuntu16.04下docker修改配置文件不生效解决办法
- ubuntu下安装vsftpd及vsftpd配置文件不见的解决办法
- struts2中validator配置文件验证不起作用的问题解决办法、根源
- ubuntu下安装vsftpd及vsftpd配置文件不见的解决办法
- ubuntu下修改 vim 配置 将 .inc 后缀文件 动态当作不同文件对待的解决办法
- vs 打开项目时要建配置文件的解决办法
- 虚拟机下Ubuntu安装VMWare Tools出现错误“找不到kernel header文件路径”解决办法
- windows7使用临时配置文件登录的解决办法
- Ubuntu“无法解析或打开软件包的列表或是状态文件”的解决办法。
- Ubuntu 10.10安装VMware Tools出现错误“找不到kernel header文件路径”的解决办法
- IIS7.5由于权限不足而无法读取配置文件的解决办法
- 解决Ubuntu下chrome无法打开配置文件的错误
- eclipse开发spring配置文件xml代码不提示的解决办法
- windos文件上传ubuntu出现乱码解决办法
- 动软代码生成器,出现”添加服务器配置失败,请检查是否有写入权限或文件是否存在“的错误的解决办法
- Struts2配置文件中redirect传递中文参数乱码的解决办法!
- 打SharePoint 2010 SP1后访问用户配置文件同步服务应用程序出错的解决办法
- ubuntu下Gedit文本编辑器查看txt文件乱码的解决办法
- MyEclipse 打开Struts配置文件时出错的终级解决办法
- VMware8安装ubuntu 12.04 不能共享文件解决办法