uos安装docker

最近需要在uos上部署系统,考虑用docker会简单一些,但uos默认没有docker,于是尝试安装。两种安装方法,1是改安装源地址然后yum或dnf安装;2是手动下载静态包安装。原则上1简单一些,但为了更好理解docker的运行逻辑,选择了2.

 

下载docker

wget -c https://download.docker.com/linux/static/stable/x86_64/docker-25.0.4.tgz

具体的文件版本可通过网址直接查看。

 

解压压缩包

tar zxvf docker-25.0.4.tgz
mv docker/* /usr/local/bin

 

配置docker

mv docker /etc
mkdir docker /home

编辑/etc/docker/daemon.json

{
    "data-root": "/home/docker",
    "dns" : [
        "114.114.114.114",
        "8.8.8.8"
    ],
    "registry-mirrors": [
            "https://docker.mirrors.ustc.edu.cn/",
            "https://hub-mirror.c.163.com/",
            "https://reg-mirror.qiniu.com"
    ],
    "log-driver":"json-file",
    "log-opts": {"max-size":"500m", "max-file":"3"}
}

 

配置docker自启动

创建以下文件:

containerd.service:

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target

 

docker.service:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
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/local/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=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.
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

 

docker.socket:

[Unit]
Description=Docker Socket for the API

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

 

将以上三个文件放入/etc/systemd/system,然后执行如下指令:

systemctl enable containerd.service
systemctl enable docker.socket
systemctl enable docker.service

 

使非root用户也能使用docker[optional]

groupadd docker
usermod -aG docker $USER   # 此处$USER即为想添加使用docker的用户名

 

重启电脑后即可正常使用docker。此时可通过如下指令运行redis和mysql容器,其中‘ASDfgh123'字串为二者密码,可根据需要修改。

docker run --name redis -p 6379:6379 --restart=always -d redis --requirepass ASDfgh123

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=ASDfgh123 -e MYSQL_ROOT_HOST='%' --restart=always -d mysql

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章