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. 模板—Hash_map

    struct Hash_map { ],nx[]; ];]; inline double &operator [] (int x) { ,i=fi[k]; for(;i&&st ...

  2. 请求(RequestInfo)

    请求类型 StringRequestInfo 用在 SuperSocket 命令行协议中. 你也可以根据你的应用程序的需要来定义你自己的请求类型. 例如, 如果所有请求都包含 DeviceID 信息, ...

  3. laravel 授权使用gate门类

    第一:先注册 第二:使用方式三种 路由中:Route::group(['middleware'=>'can:system'],function() {}) 模板中:@can("syst ...

  4. 【JQ】toggle / slideToggle / fadeToggle 的区别

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. artTemplate模版引擎的使用

    artTemplate: template.js 一款 JavaScript 模板引擎,简单,好用.提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不 ...

  6. IDEA中安装activiti并使用

    1.IDEA中本身不带activiti,需要自己安装下载. 打开IDEA中File列表下的Settings 输入actiBPM,然后点击下面的Search...搜索 点击Install 下载 下载结束 ...

  7. H3C LMI

  8. Math.abs( x )

    Math.abs( x ) 下面是参数的详细信息: x : 一个数字 返回值: 返回一个数字的绝对值 <html> <head> <title>JavaScript ...

  9. Git篇

    安装之后第一步 安装 Git 之后,你要做的第一件事情就是去配置你的名字和邮箱,因为每一次提交都需要这些信息: git config --global user.name "bukas&qu ...

  10. Vue的第一个实例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...