linux服务器离线安装docker?在无apt-get,curl,yum等工具命令包情况下离线安装!

此文整理下当初安装docker的动作

Linux 服务器Docker安装

1. 安装包官方地址:https://download.docker.com/linux/static/stable/x86_64/

可以先下载到本地,然后通过ftp工具shell中的ftp工具上传到服务器上

2. 解压:tar -zxvf docker-18.06.3-ce.tgz

3. 将解压出来的docker文件复制到 /usr/bin/ 目录下

4. 创建docker.service文件

进入 /etc/systemd/system/ 目录,  并创建 docker.service 文件,sudo touch docker.service

内容如下,这样可以将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=127.0.0.1
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

# 此处的–insecure-registry=127.0.0.1(此处改成你私服ip)设置是针对有搭建了自己私服Harbor时允许docker进行不安全的访问,否则访问将会被拒绝。
5. 启动docker
# 给docker.service文件添加执行权限
chmod +x /etc/systemd/system/docker.service
# 重新加载配置文件(每次有修改docker.service文件时都要重新加载下)
systemctl daemon-reload
# 启动
systemctl start docker
# 设置开机启动
systemctl enable docker.service
# 查看docker服务状态
[root@localhost system]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-06-28 00:54:47 PDT; 10s ago
Docs: https://docs.docker.com
Main PID: 45475 (dockerd)
CGroup: /system.slice/docker.service
├─45475 /usr/bin/dockerd --selinux-enabled=false --insecure-registry=10.1.20.150
└─45487 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
Jun 28 00:54:46 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:46.158519178-07:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd..." module=grpc
Jun 28 00:54:46 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:46.158525449-07:00" level=info msg="ClientConn switching balancer to "pick_first"" module=grpc
Jun 28 00:54:46 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:46.202943588-07:00" level=info msg="Loading containers: start."
Jun 28 00:54:47 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:47.021854086-07:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon...d IP address"
Jun 28 00:54:47 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:47.126281901-07:00" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
Jun 28 00:54:47 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:47.244251569-07:00" level=info msg="Loading containers: done."
Jun 28 00:54:47 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:47.264592112-07:00" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=overlay2 version=20.10.17
Jun 28 00:54:47 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:47.265027319-07:00" level=info msg="Daemon has completed initialization"
Jun 28 00:54:47 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Jun 28 00:54:47 localhost.localdomain dockerd[45475]: time="2022-06-28T00:54:47.300116789-07:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
# 如上表示docker已安装成功
6. docker环境检查
docker info
[root@localhost system]# docker info
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.17
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc version: v1.1.2-0-ga916309f
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.624GiB
Name: localhost.localdomain
ID: ZHES:U53P:FOPX:QKRO:4PQE:BIKC:OEQJ:7VUS:NBUQ:U47D:R3QO:JKKX
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
10.1.20.150
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
docker version
[root@localhost system]# docker version
Client:
Version:           20.10.17
API version:       1.41
Go version:        go1.17.11
Git commit:        100c701
Built:             Mon Jun  6 22:56:42 2022
OS/Arch:           linux/amd64
Context:           default
Experimental:      true
Server: Docker Engine - Community
Engine:
Version:          20.10.17
API version:      1.41 (minimum version 1.12)
Go version:       go1.17.11
Git commit:       a89b842
Built:            Mon Jun  6 23:01:45 2022
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          v1.6.6
GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version:          1.1.2
GitCommit:        v1.1.2-0-ga916309f
docker-init:
Version:          0.19.0
GitCommit:        de40ad0

7. 安装好docker后还不能直接用docker命令,此时需要创建一个docker的group

sudo usermod -aG docker $USER ($USER就是当前登录服务器的用户名);

这里可能会出现一个错误:usermod: group 'docker' does not exist
这是因为在安装docker的使用如果使用npm install来安装,它是不会给你创建docker的group的,所以我们需要自己创建一个;

如果报错执行:sudo groupadd docker #创建一个docker的group;

然后再执行添加用户操作就可以成功了,最后重启docker
sudo usermod -aG docker ${USER}
sudo systemctl restart docker

注销并重新登录,或者运行以下命令以更新当前会话的用户组成员身份
newgrp docker

8. 以上可以直接用docker命令来安装啦,无需再加sudo命令~

9. 安装docker compose

# docker-compose下载并放到/usr/local/bin/下面:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 下载好docker-compose的前提下,拷贝到指定位置
sudo cp docker-compose /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
docker-compose -v
# 最后使用 docker-compose -v 命令测试是否安装成功(如果提示“没有那个文件或目录”可以重启下服务器再试试)

查看docker compose的版本

docker-compose -v

如下

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
非常感谢您的提问。要在Linux服务器上安装Docker,您需要执行以下步骤: 1. 升级服务器并安装必要的软件 - 在Ubuntu上:运行“sudo apt-get update”和“sudo apt-get upgrade”命令更新软件 - 在CentOS上:运行“sudo yum update”命令更新软件 - 安装必要的软件curl,apt-transport-https,ca-certificates,software-properties-common 2. 添加Docker官方GPG key - 执行以下命令导入Docker GPG key: ``` curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` 3. 添加Docker稳定软件源 - 在Ubuntu 20.04上:运行“sudo add-apt-repository 'deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable'”命令 - 在Ubuntu 18.04上:运行“sudo add-apt-repository 'deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable'”命令 - 在CentOS上:运行以下命令添加DockerCE软件仓库: ``` sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo ``` 4. 安装Docker CE - 在Ubuntu上:运行“sudo apt-get update”和“sudo apt-get install docker-ce”命令 - 在CentOS上:运行“sudo yum install -y docker-ce”命令 5. 启动并测试Docker CE - 在Ubuntu上:运行“sudo systemctl start docker命令启动Docker服务,并运行“sudo docker run hello-world”命令测试Docker是否安装成功 - 在CentOS上:运行“sudo systemctl start docker命令启动Docker服务,并运行“sudo docker run hello-world”命令测试Docker是否安装成功 希望这份指南能够对您有所帮助。如果您有任何其他问题或疑虑,请随时让我知道。谢谢!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值