vi /lib/systemd/system/docker.service

docker.service默认内容如下:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
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/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity # Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes # kill only the docker process, not all processes in the cgroup
KillMode=process [Install]
WantedBy=multi-user.target

下面的配置都是在[Service]节点下的ExecStart属性后面加参数值,docker.service文件被修改后请执行systemctl daemon-reload && systemctl restart docker,如果配置未生效,请执行systemctl status docker查看服务状态。

开启远程API访问端口

添加-H 0.0.0.0:2375,端口可以随意指定,修改后的ExecStart如下:

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

重新加载配置并重启docker

systemctl daemon-reload && systemctl restart docker

访问http://127.0.0.1:2375/info进行验证

修改bridge网络的ip段

执行docker network inspect bridge命令可以发现bridge网络默认的IP段是172.17.0.0/16,添加--bip 10.0.0.1/16修改默认IP段

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --bip 10.0.0.1/16

重新加载配置并重启docker

systemctl daemon-reload && systemctl restart docker

启动一个nginx容器进行验证

docker run -dP --name nginx nginx
docker inspect --format '{{ .NetworkSettings.IPAddress }}' nginx
docker rm -f nginx

配置私有镜像仓库

以下示例配置develop-harbor.geostar.com.cntest-harbor.geostar.com.cnrelease-harbor.geostar.com.cn三个私有镜像仓库

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock \
--insecure-registry develop-harbor.geostar.com.cn \
--insecure-registry test-harbor.geostar.com.cn \
--insecure-registry release-harbor.geostar.com.cn \

重新加载配置并重启docker

systemctl daemon-reload && systemctl restart docker

手动拉取私有镜像仓库中的镜像验证

配置dns

以下示例配置114.114.114.114 8.8.8.8两个dns服务器地址

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock \
--dns 114.114.114.114 \
--dns 8.8.8.8

重新加载配置并重启docker

systemctl daemon-reload && systemctl restart docker

启动一个alpine容器镜像验证resolv.conf配置文件是否成功修改

docker run --rm alpine cat /etc/resolv.conf

docker.service 修改指南的更多相关文章

  1. Linux Mint安装Docker踩坑指南

    我家的服务器选用的Linux Mint系统,最近安装Docker的时候踩了一些小坑,但是总体还算顺利. 我们都知道Linux Mint系统是基于Ubuntu的,说实话用起来感觉还是很不错的,安装Doc ...

  2. docker日常使用指南

    docker日常使用指南 目录 docker日常使用指南 前言 1.基础知识 1.1 docker是什么 1.2 与虚拟机(VM)的区别 1.3 镜像与容器 2.安装 2.1 在线安装 2.2 离线安 ...

  3. Docker - 通过swarm 管理 docker service

    创建一个 Docker service $ docker service create --replicas 1 --name myhelloworld alpine ping docker.com ...

  4. CentOS启动docker1.13失败(Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.)

    一.启动失败 1.启动docker [root@localhost ~]# systemctl start docker Job for docker.service failed because t ...

  5. Failed to start docker.service: Unit not found.

    安装教程参考: https://docs.docker.com/install/linux/docker-ce/centos/#install-docker-ce-1 https://yq.aliyu ...

  6. Docker(十七)-修改Docker容器启动配置参数

    有时候,我们创建容器时忘了添加参数 --restart=always ,当 Docker 重启时,容器未能自动启动, 现在要添加该参数怎么办呢,方法有二: 1.Docker 命令修改 docker c ...

  7. docker探索-使用docker service管理swarm(十一 )

    本文转自:https://www.cnblogs.com/atuotuo/p/6265541.html 1.创建一个 Docker service $ docker service create -- ...

  8. Docker: 如何修改 Docker 的镜像存储位置

    我用的阿里云的服务器, 但是系统盘只有20G, 默认 Docker 的镜像文件是安装在/var/lib 目录下的, 这样的话我根本装不了太多的镜像... 这个必须得改改... 搜了下, 解决方案如下: ...

  9. CentOS7 启动docker.service失败(code=exited, status=1/FAILURE)

    启动报错 Job for docker.service failed because the control process exited with error code. See "sys ...

随机推荐

  1. 爬虫:Selenium + PhantomJS

    更:Selenium特征过多(language/UserAgent/navigator/en-US/plugins),以Selenium打开的浏览器处于自测模式,很容易被检测出来,解决方法可选: 用m ...

  2. Python深入:Distutils安装包

    一:简介 尽管Python标准库已经支持很多的功能,但是有时还是会需要以第三方模块的形式添加新的功能到Python中. 在最简单的场景中,是你要安装的模块,已经有了针对你的平台的安装版本,因此只需要像 ...

  3. 数据库设计mysql字段不默认为NULL原因搜集

    索引不会包含有NULL值的列 只要列中包含有NULL值都将不会被包含在索引中,复合索引中只要有一列含有NULL值,那么这一列对于此复合索引就是无效的.所以我们在数据库设计时不要让字段的默认值为NULL ...

  4. laravel asset()函数

    asset() 使用当前请求的scheme(HTTP或HTTPS)为前端资源生成一个URL: $url = asset('img/photo.jpg'); laravel自带了laravel-mix, ...

  5. Element-ui学习笔记3--Form表单(二)

    Input输入框 Input 为受控组件,它总会显示 Vue 绑定值. 通常情况下,应当处理 input 事件,并更新组件的绑定值(或使用v-model).否则,输入框内显示的值将不会改变. 不支持  ...

  6. H3C 配置PAP验证

  7. [转]React入门看这篇就够了

    摘要: 很多值得了解的细节. 原文:React入门看这篇就够了 作者:Random Fundebug经授权转载,版权归原作者所有. React 背景介绍 React 入门实例教程 React 起源于 ...

  8. Python--day25--面向对象之多态

    多态(Python天生支持多态) 多态指的是一类事物有多种形态 动物有多种形态:人,狗,猪 import abc class Animal(metaclass=abc.ABCMeta): #同一类事物 ...

  9. 2018-8-10-C#-判断文件编码

    title author date CreateTime categories C# 判断文件编码 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 17:23: ...

  10. Oracle备库宕机启动解决方案

    简介 ORA-10458: standby database requires recovery ORA-01196: 文件 1 由于介质恢复会话失败而不一致 ORA-01110: 数据文件 1: ' ...