0
点赞
收藏
分享

微信扫一扫

将docker注册为 Systemd 的 service [root@localhost ~]# cat >

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.9.2009 (Core)

[root@localhost ~]# uname -r

3.10.0-1160.el7.x86_64

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i.bak '7s/enforcing/disabled/' /etc/selinux/config

[root@localhost ~]# swapoff -a

[root@localhost ~]# sed -ri.bak 's/.*swap.*/#&/' /etc/fstab

[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld

[root@localhost ~]# firewall-cmd --state

not running

# 更换阿里源

[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo

# 下载 Docker docker-23.0.6.tgz 为例 (当前最新版本 docker-27.2.0.tgz)

[root@localhost ~]# wget https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-23.0.6.tgz

[root@localhost ~]# tar -xf docker-23.0.6.tgz

[root@localhost ~]# cp docker/* /usr/bin/

 

[root@localhost ~]# docker -v

Docker version 23.0.6, build ef23cbc

[root@localhost ~]# docker -h

 

# 将docker注册为 Systemd 的 service

[root@localhost ~]# cat > /etc/systemd/system/docker.service <<EOF

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service

Wants=network-online.target

 

[Service]

Type=notify

# the default is www.laipuhuo.com.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 unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536

ExecReload=/bin/kill -s HUP $MAINPID

# 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

# Uncomment TasksMax if your systemd version supports it.

# Only systemd 226 and above support this version.

#TasksMax=infinity

TimeoutStartSec=0

# set delegate yes www.laipuhuo.com.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

# restart the docker process if it exits prematurely

Restart=on-failure

StartLimitBurst=3

StartLimitInterval=60s

 

[Install]

WantedBy=multi-user.target

# 如果需要开启远程服务ExecStart属性修改为以下命令:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536

# -H tcp://0.0.0.0:2375 开启远程连接命令


# 添加文件可执行权限

[root@localhost ~]# chmod +x /etc/systemd/system/docker.service

# 添加国内镜像加速(每次修改需重启 docker)

[root@localhost ~]# mkdir /etc/docker

[root@localhost www.laipuhuo.com. ~]# cat > /etc/docker/daemon.json <<EOF

{

   "registry-mirrors": [

       "https://mirror.baidubce.com",

       "https://mirror.ccs.tencentyun.com",

       "https://wxvmh7l6.mirror.aliyuncs.com",

       "https://hub.atomgit.com",

       "https://registry.docker-cn.com",

       "https://mirrors.tuna.tsinghua.edu.cn",

       "http://hub-mirror.c.163.com",

       "https://docker.mirrors.ustc.edu.cn"

   ]

}

EOF

 

# 启动

[root@localhost ~]# systemctl daemon-reload && systemctl start docker

 

# 测试 Docker 是否安装正确

[root@localhost ~]# docker run --rm hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

d195baed67eb: Pull complete

Digest: sha256:www.laipuhuo.com.be06e3c4ce8780c0f87fbf66ec9b34623ba2fd14caa5559be5b593653821b814

Status: Downloaded newer image for hello-world:latest

 

Hello from Docker!

This message shows that your installation appears to be working correctly.

 

To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.

2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

   (amd64)

3. The Docker daemon created a new container from that image which runs the

   executable that produces the output you are currently reading.

4. The Docker daemon streamed that output to the Docker client, which sent it

   to your terminal.

To try something www.laipuhuo.com.more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash

Share images, [root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.9.2009 (Core)

[root@localhost ~]# uname -r

3.10.0-1160.el7.x86_64

 

[root@localhost ~]# setenforce 0

[root@localhost ~]#www.laipuhuo.com. sed -i.bak '7s/enforcing/disabled/' /etc/selinux/config

 

[root@localhost ~]# swapoff -a

[root@localhost ~]# sed -ri.bak 's/.*swap.*/#&/' /etc/fstab

 

[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld

[root@localhost ~]# firewall-cmd --state

not running

 

# 更换阿里源

[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 

automate workflows, www.laipuhuo.com.and more with a free Docker ID:

For more examples and ideas, visit: h

若能正常输出以上信息,则说明安装成功。

举报

相关推荐

0 条评论