docker

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const PruneDockerShell = `` /* 382-byte string literal not displayed */

PruneDockerShell todo: optimize

Variables

View Source
var DockerConfigTmpl = template.Must(template.New("DockerConfigTmpl").Parse(dedent.Dedent(`
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<EOF
{
  "log-opts": {
    "max-size": "500m",
    "max-file":"3"
  },
  "userland-proxy": false,
  "live-restore": true,
  "default-ulimits": {
    "nofile": {
      "Hard": 65535,
      "Name": "nofile",
      "Soft": 65535
    }
  },
  "default-address-pools": [
    {
      "base": "172.80.0.0/16",
      "size": 24
    },
    {
      "base": "172.90.0.0/16",
      "size": 24
    }
  ],
  "default-gateway": "",
  "default-gateway-v6": "",
  "default-runtime": "runc",
  "default-shm-size": "64M",
  {{- if .DataPath }}
  "data-root": "{{ .DataPath }}",
  {{- end}}
  {{- if .Mirrors }}
  "registry-mirrors": [{{ .Mirrors }}],
  {{- end}}
  {{- if .InsecureRegistries }}
  "insecure-registries": [{{ .InsecureRegistries }}],
  {{- end}}
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
`)))

DockerConfigTmpl [1]DataPath 持久化数据目录 [2]Mirrors 镜像源 [3]InsecureRegistries http镜像仓库列表

View Source
var InstallDockerTmpl = template.Must(template.New("InstallDockerTmpl").Parse(dedent.Dedent(`
{{- if .Package }}
cd /tmp
tar zxvf /tmp/{{ .Package }}
\cp /tmp/docker/* /usr/bin/
{{- end }}
`)))
View Source
var SetDockerServiceTmpl = template.Must(template.New("SetDockerServiceTmpl").Parse(dedent.Dedent(`
tee /usr/lib/systemd/system/docker.service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
EOF

tee /lib/systemd/system/containerd.service <<EOF
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
EOF

tee /lib/systemd/system/docker.socket <<EOF
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
EOF
`)))

Functions

func Install

func Install(item command.OperationItem) command.RunErr

Install 安装部署docker-ce

Types

type Handler

type Handler struct{}

func (Handler) Boot

func (h Handler) Boot(server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.BootErr

func (Handler) Detect

func (h Handler) Detect(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) error

func (Handler) Exec

func (h Handler) Exec(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) error

func (Handler) HandPackage

func (h Handler) HandPackage(server runner.ServerInternal, filePath string, local bool, logger *logrus.Logger, timeout time.Duration) error

func (Handler) Install

func (h Handler) Install(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.InstallErr

func (Handler) Prune

func (h Handler) Prune(server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.PruneErr

func (Handler) SetConfig

func (h Handler) SetConfig(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.SetConfigErr

func (Handler) SetSystemd

func (h Handler) SetSystemd(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.SetSystemdErr

func (Handler) SetUpRuntime

func (h Handler) SetUpRuntime(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.SetUpRuntimeErr

type HandlerInterface

type HandlerInterface interface {
	Boot(server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.BootErr
	Prune(server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.PruneErr
	Exec(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) error
	SetUpRuntime(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.SetUpRuntimeErr
	SetSystemd(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.SetSystemdErr
	SetConfig(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.SetConfigErr
	Install(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) install.InstallErr
	Detect(cmd string, server runner.ServerInternal, local bool, logger *logrus.Logger, timeout time.Duration) error
	HandPackage(server runner.ServerInternal, filePath string, local bool, logger *logrus.Logger, timeout time.Duration) error
}

type Manager

type Manager struct {
	Servers            []runner.ServerInternal
	Package            string
	PreserveDir        string
	Logger             *logrus.Logger
	ConfigContent      []byte
	Timeout            time.Duration
	Executor           runner.ExecutorInternal
	IgnoreErr          bool // UnitTest
	InsecureRegistries []string
	Mirrors            []string
	BootCommand        string

	Local   bool // 本地安装
	Handler HandlerInterface
	// contains filtered or unexported fields
}

Manager 内部对象

func (*Manager) Boot

func (m *Manager) Boot(server runner.ServerInternal) install.BootErr

Boot 启动docker服务

func (*Manager) Detect

func (m *Manager) Detect(server runner.ServerInternal) (err command.RunErr)

Detect 调用运行时检测依赖

func (*Manager) HandPackage

func (m *Manager) HandPackage(server runner.ServerInternal) (err command.RunErr)

HandPackage 分发安装包 todo: mock

func (*Manager) Install

func (m *Manager) Install(server runner.ServerInternal) install.InstallErr

Install 安装

func (*Manager) Parse

func (m *Manager) Parse() (*Manager, error)

Parse todo: return Config object

func (*Manager) Prune

func (m *Manager) Prune(server runner.ServerInternal) install.PruneErr

Prune 清理历史文件 todo: mock

func (*Manager) SetConfig

func (m *Manager) SetConfig(server runner.ServerInternal) install.SetConfigErr

SetConfig 配置/etc/docker/daemon.json

func (*Manager) SetSystemd

func (m *Manager) SetSystemd(server runner.ServerInternal) install.SetSystemdErr

SetSystemd 配置systemd服务

func (*Manager) SetUpRuntime

func (m *Manager) SetUpRuntime(server runner.ServerInternal) install.SetUpRuntimeErr

SetUpRuntime docker运行时配置

type ManifestConfig

type ManifestConfig struct {
	Docker struct {
		Package            string   `yaml:"package"`
		PreserveDir        string   `yaml:"preserveDir"`
		InsecureRegistries []string `yaml:"insecureRegistries"`
		RegistryMirrors    []string `yaml:"registryMirrors"`
	} `yaml:"docker"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL