【docker 安装】 与【docker-compose 安装】

不同的操作系统需要不同的docker安装文件:具体下载位置:

Docker: https://download.docker.com/linux/static/stable/

docekr-compose:https://github.com/docker/compose/releases

1. 验证客户机器是否有docker 和docker-compose

powershell 复制代码
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安装

  1. 将压缩包上传到服务器并解压
powershell 复制代码
tar -zxvf xxx.taz 
  1. 拷贝docker文件夹至/usr/bin/下
powershell 复制代码
cp docker/* /usr/bin/
  1. 拷贝docker.service文件夹至/etc/systemd/system/下()

docker.service:

python 复制代码
[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
powershell 复制代码
cp docker.service  /etc/systemd/system/
  1. 查看本机ip
powershell 复制代码
ifconfig

>>---
enp5s0: flags=4163<UP,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<link>
        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
  1. 修改/etc/systemd/system/docker.service
powershell 复制代码
vim /etc/systemd/system/docker.service

修改对应位置配置,保存退出。

python 复制代码
[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
  1. 添加执行权限 /etc/systemd/system/docker.service
powershell 复制代码
chmod +x /etc/systemd/system/docker.service
  1. 重新加载服务配置文件
powershell 复制代码
systemctl daemon-reload 
  1. 设置开机启动
powershell 复制代码
systemctl enable docker.service
  1. 启动docker
powershell 复制代码
systemctl start docker
  1. 查看docker状态
powershell 复制代码
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
  1. 查看docker版本
powershell 复制代码
docker -v 

>>>
 输出Docker版本号安装成功>>  Docker version 20.10.12, build 3967b7d 
安装成功

1.2 docker-compose安装

  1. 将docker-compose文件移动到/usr/local/bin/下
powershell 复制代码
sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
  1. 赋予可执行权限
powershell 复制代码
sudo chmod +x /usr/local/bin/docker-compose 
  1. 查看版本验证是否成功
powershell 复制代码
docker-compose -v
输出Docker-compse版本号安装成功>> docker-compose version 1.29.2, build 5becea4c
  1. 验证当前用户是否有docker,docker-compose命令权限.
    2.1 当前用户执行docker命令 验证:
powershell 复制代码
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组用户:

powershell 复制代码
cat /etc/group  | grep docker

>>>
docker:x:999:<username>

如果有docker用户组,且当前用户不在docker用户组中,将当前用户加入到docker用户组中,并更新用户组,重启docker。

powershell 复制代码
# 新建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执行权限:

powershell 复制代码
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)

若当前用户没有可执行权限:

powershell 复制代码
sudo chmod a+x /usr/local/bin/docker-compose
相关推荐
用户0328472220701 天前
如何搭建本地yum源(上)
运维
武子康1 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
大树884 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠4 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质4 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
Inhand陈工4 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信
Alsn864 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
酣大智4 天前
ARP代理--工作原理
运维·网络·arp·arp代理
shushangyun_4 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
施努卡机器视觉4 天前
SNK施努卡侧滑门锁上滑轮总成自动化装配线,从零件到组件,全流程精密制造方案
运维·自动化·制造