Docker环境配置

docker可视化搭建

准备软件包:
docker下载官网:https://download.docker.com/linux/static/stable/
根据自己操作系统架构选择软件包,本次实验使用x86_64-docker-23.0.1.tgz

docker安装

配置docker服务文件

[root@localhost ~]# vi /etc/systemd/system/docker.service

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewall.service

Wants=network-online.target

[Service]

Type=notify

#the default is not to use systemd for cgroups because the delegay issues still

#exists and systemd currently does not support the cgroup feature set required

#for containers run by docker

ExecStart=/usr/bin/dockerd

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 so that systemd does not reset the cgroups of docker containers

Delegate=yes

#kill only the docker process, not all process 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

上传docker-23.0.1.tgz至云服务器

[root@localhost ~]# tar -zxvf docker-23.0.1.tgz
[root@localhost ~]# mv docker/* /usr/bin
[root@localhost ~]# chmod +x /etc/systemd/system/docker.service
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker

镜像加速器

启动docker后拉取镜像速度很慢,需要配置国内的镜像加速器

[root@localhost ~]# sudo mkdir -p /etc/docker
[root@localhost ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://mqsapo5u.mirror.aliyuncs.com"]
}
EOF
[root@localhost ~]# sudo systemctl daemon-reload
[root@localhost ~]# sudo systemctl restart docker

可视化管理

在docker中搭建可视化管理工具
需要准备汉化包:Portainer-CN2021-IMNKS.COM-20211018.zip

[root@localhost ~]# unzip Portainer-CN2021-IMNKS.COM-20211018.zip
[root@localhost ~]# mv public/* /opt/portainer/public/
[root@localhost ~]# docker pull portainer/portainer
[root@localhost ~]# docker run -itd --restart=always --name portainer -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data -v /opt/portainer/public:/public portainer/portainer

在浏览器输入http://IP:9000/
在导入汉化包之后可能会出现docker没有完成初始化的情况
这时候需要重启一下docker并关闭当前浏览器重新进行初始化

systemctl restart docker
posted @ 2023-03-30 08:24  陌熊  阅读(79)  评论(0)    收藏  举报