CentOS7.9安装docker和docker-compose以及Harbor

1.首先查看linux版本

[root@localhost ~]# cat /proc/version
Linux version 3.10.0-1160.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# lsb_release -a
-bash: lsb_release: 未找到命令
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

2.更新yum

[root@localhost ~]# yum update -y

3.安装wget,curl

[root@localhost ~]#  yum install -y wget curl

4.设置docker yum源 并安装 docker

[root@localhost ~]# yum-config-manager     --add-repo \
     https://download.docker.com/linux/centos/docker-ce.repo

[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io

5.启动docker

[root@localhost ~]# systemctl enable docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl status docker
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.13
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 10 14:09:51 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.13
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       906f57f
  Built:            Thu Mar 10 14:08:16 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.10
  GitCommit:        2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

5.安装docker-compose

   [root@localhost ~]# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" \ 
-o /usr/local/bin/docker-compose
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
[root@localhost ~]# ll /usr/local/bin
[root@localhost ~]# docker-compose --version
docker-compose version 1.29.2, build 5becea4c

6.运行docker helloworld

[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:4c5f3db4f8a54eb1e017c385f683a2de6e06f75be442dc32698c9bbe6c861edd
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

7.设置阿里云docker加速镜像

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

8.下载Harbor 并安装

[root@localhost ~]# cd /opt # 将harbor离线安装文件复制到当前目录下
[root@localhost opt]# tar -zvxf harbor-offline-installer-v2.4.1.tgz
[root@localhost opt]# cd harbor
[root@localhost harbor]# pwd
/opt/harbor
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml

hostname: 192.168.20.133
harbor_admin_password: Harbor12345
#https配置全部注释掉,如果想要开启https协议,可以配置一下证书
# https related config
#https:
# https port for harbor, default is 443
#  port: 443
# The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path

[root@localhost harbor]# ./prepare

[root@localhost harbor]# ./install.sh
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry      ... done
Creating redis         ... done
Creating registryctl   ... done
Creating harbor-portal ... done
Creating harbor-db     ... done
Creating harbor-core   ... done
Creating nginx             ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----
出现上面的信息代表Harbor安装成功

9.配置harbor开机启动

[root@localhost ~]# vim /lib/systemd/system/harbor.service
[Unit]
Description=Harbor
After=docker.service
Requires=docker.service
Documentation=http://github.com/vmware/harbors

[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/bin/docker-compose -f  /opt/harbor/docker-compose.yml up
ExecStop=/usr/bin/docker-compose -f /opt/harbor/docker-compose.yml down

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl enable harbor

10.配置harbor http能访问

[root@localhost lib]# vim /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://wh9z3wm8.mirror.aliyuncs.com",
  ],
  "insecure-registries": [
    "192.168.20.133:85"
  ]
}

11.防火墙增加端口放开权限

[root@localhost share]# firewall-cmd --permanent --zone=public --add-port=85/tcp
success
[root@localhost share]# systemctl reload firewalld

12.手动启动或停止Harbor

[root@localhost harbor]# pwd
/opt/harbor
[root@localhost harbor]# ls
common  common.sh  docker-compose.yml  harbor.v2.4.1.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@localhost harbor]# docker-compose down #手动停止
[root@localhost harbor]# docker-compose up -d #手动开启

13.访问Harbor

CentOS7.9安装docker和docker-compose以及Harbor_第1张图片

CentOS7.9安装docker和docker-compose以及Harbor_第2张图片

 

 

你可能感兴趣的:(docker,docker,阿里云,linux)