不同的操作系统需要不同的docker安装文件:具体下载位置:
Docker: https://download.docker.com/linux/static/stable/
docekr-compose:https://github.com/docker/compose/releases
docker -v
输出Docker版本号成功>> Docker version 20.10.12, build 3967b7d
docker-compose -v
输出Docker-compse版本号成功>> docker-compose version 1.29.2, build 5becea4c
1.1 docker安装
tar -zxvf xxx.taz
cp docker/* /usr/bin/
docker.service:
[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 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 --selinux-enabled=false --insecure-registry=192.168.31.242
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 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
cp docker.service /etc/systemd/system/
ifconfig
>>---
enp5s0: flags=4163,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.31.242 netmask 255.255.255.0 broadcast 192.168.31.255
inet6 fe80::7656:3cff:fe27:4006 prefixlen 64 scopeid 0x20
ether 74:56:3c:27:40:06 txqueuelen 1000 (Ethernet)
RX packets 50821046 bytes 52119283120 (52.1 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 65044588 bytes 45372132281 (45.3 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vim /etc/systemd/system/docker.service
修改对应位置配置,保存退出。
[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 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 --selinux-enabled=false --insecure-registry=192.168.31.242
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 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
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload
systemctl enable docker.service
systemctl start docker
systemctl status docker
>>>
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-09-17 09:29:46 UTC; 1 years 10 months ago
Docs: https://docs.docker.com
docker -v
>>>
输出Docker版本号安装成功>> Docker version 20.10.12, build 3967b7d
安装成功
sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose -v
输出Docker-compse版本号安装成功>> docker-compose version 1.29.2, build 5becea4c
docker ps
>>>
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied
根据报错信息(/var/run/docker.sock: connect: permission denied),可知,用户无操作权限。
若可以正常执行则忽略此处
2.1.1 查看docker组用户:
cat /etc/group | grep docker
>>>
docker:x:999:
如果有docker用户组,且当前用户不在docker用户组中,将当前用户加入到docker用户组中,并更新用户组,重启docker。
# 新建docker组,若存在,则忽略
groupadd docker
# 修改docker.sock权限为root:docker
sudo chown root:docker /var/run/docker.sock
#将用户添加到docker组
sudo usermod -aG docker ${USER}
#更新用户组
newgrp docker
#重启docker
systemctl daemon-reload
systemctl restart docker
2.2 docker-compose权限设置
查看docker-compose执行权限:
ll /usr/local/bin/ |grep docker-compose
>>>
-rwxr-xr-x 1 root root 8856808 Mar 10 02:11 docker-compose*
docker-compose 属于root , root在用户组root中。 root用户可读可写可执行(rwx)
root组其用户可读不可写可执行(r-x)。 其他用户可读不可写可执行(r-x)
若当前用户没有可执行权限:
sudo chmod a+x /usr/local/bin/docker-compose