基础环境安装
本次示例是在Centos中安装
- 旧版本的卸载docker
yum -y remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 设置存储库
yum install -y yum-utils &>/dev/null
- 设置镜像的仓库
#(默认是国外的!在你安装Docker引擎时特别特别慢)
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 推荐使用阿里国内源安装docker
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# 更新软件包索引
yum makecache fast
- 安装最新的Docker引擎 docker-ce:社区版 ee企业版
yum -y install docker-ce docker-ce-cli containerd.io
systemctl start docker && systemctl enable docker
使用docker version查看版本
[root@localhost harbor]# docker version
Client: Docker Engine - Community
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:49:57 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:48:24 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Compose是一个用于定义和运行多容器Docker应用程序的工具。通过编写,您可以使用YAML文件配置应用程序的服务。然后,使用一个命令就可以从yml文件配置中创建并启动配置中的所有服务。
Compose在所有环境中编写工作:生产、分期、开发、测试以及CI工作流。
使用Compose基本上是一个三步的过程:
- 用
Dockerfile
定义应用程序的环境,这样它就可以在任何地方复制。 - 在
docker-compose.yml
中定义构成应用程序的服务。这样它们就可以在一个孤立的环境中一起运行。 - 运行
docker-compose up
然后编写、启动和运行整个应用程序。
作用:批量容器服务编排。
官网安装地址
# 1、下载DockerCompose当前的稳定版本
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose #国外比较慢
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose #国内比较快
# 2、授权
chmod +x /usr/local/bin/docker-compose
注*如果命令docker-compose安装后失败,请检查您的路径。您还可以创建一个指向/usr/bin或者路径中的任何其他目录。
例如:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# 3、测试安装
docker-compose --version
【1】编写认证shell,auth.sh
#!/bin/bash
mkdir -p /data/cert
cd /data/cert
openssl genrsa -out /data/cert/ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=121.37.255.40" -key ca.key -out ca.crt
openssl genrsa -out /data/cert/$1.key 4096
openssl req -sha512 -new -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=$1" -key /data/cert/$1.key -out /data/cert/$1.csr
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = IP:$1
EOF
openssl x509 -req -sha512 -days 3650 -extfile /data/cert/v3.ext -CA /data/cert/ca.crt -CAkey /data/cert/ca.key -CAcreateserial -in /data/cert/$1.csr -out /data/cert/$1.crt
openssl x509 -inform PEM -in /data/cert/$1.crt -out /data/cert/$1.cert
mkdir -p /etc/docker/certs.d/$1/
cp /data/cert/$1.cert /etc/docker/certs.d/$1/
cp /data/cert/$1.key /etc/docker/certs.d/$1/
cp /data/cert/$1.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
【2】运行auth.sh
chmod +x auth.sh #添加执行权限
./auth.sh 192.168.235.10 #(192.168.235.10 表示安装harbor的地址,是传递给auth.sh的参数)
【3】修改daemon.json
添加一行insecure-registries配置即可,允许使用安全方式访问Harbor镜像仓库
#192.168.235.10表示harbor仓库的地址
echo '' > /etc/docker/daemon.json
sudo tee /etc/docker/daemon.json <<-'EOF'
{ "registry-mirrors": ["https://cy1sz59q.mirror.aliyuncs.com"] }
{ "insecure-registries":["192.168.235.10"] }
EOF
到Github上获取自己想要安装的版本
wget https://github.com/goharbor/harbor/releases/download/v2.4.2/harbor-online-installer-v2.4.2.tgz
【1】解压
[root@localhost ~]# tar -zxvf harbor-online-installer-v2.4.2.tgz
[root@localhost ~]# cd harbor
[root@localhost harbor]# ll
总用量 56
drwxr-xr-x. 3 root root 20 4月 6 18:34 common
-rw-r--r--. 1 root root 3361 3月 15 11:51 common.sh
-rw-r--r--. 1 root root 5889 4月 6 21:52 docker-compose.yml
-rw-r--r--. 1 root root 9680 4月 6 21:48 harbor.yml
-rw-r--r--. 1 root root 9668 3月 15 11:51 harbor.yml.tmpl
-rwxr-xr-x. 1 root root 2500 3月 15 11:51 install.sh
-rw-r--r--. 1 root root 11347 3月 15 11:51 LICENSE
-rwxr-xr-x. 1 root root 1881 3月 15 11:51 prepare
docker-compose.yml是安装harbor的方式,里面都是安装harbor所需要,如果我们想进行修改可以在里面进行修改,比如修改harbor的数据库
install.sh: 是一键安装harbor的指令
【2】编辑harbor配置文件
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# vi harbor.yml
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 192.168.235.10
hostname:139.159.180.189 #IP地址或者域名
# https related config(https认证)
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /data/cert/192.168.235.10.crt
private_key: /data/cert/192.168.235.10.key
【3】install.sh安装harbor
使用install.sh一键安装,因为要下载好多镜像,所以需要等待一段时间
./install.sh
docker images命令查看下安装Harbor安装的Docker镜像
在这里插入代码片
访问Harbor的管理界面,输入账号密码admin:Harbor12345
登录即可,访问地址:https://192.168.235.10/ ,并创建test项目
在这里插入代码片
使用docker login命令访问Harbor镜像仓库
输入的用户和密码是harbor的用户和密码
docker login 192.168.235.10
测试
拉取镜像mysql
docker pull mysql:8.0
使用tag指令对mysql打标签
docker tag mysql:8.0 192.168.235.10/test/mysql:8.0
将192.168.235.10/test/mysql:8.0推入到harbor的test中
docker push 192.168.235.10/test/mysql:8.0
传输完成以后在harbor中查看!
原文链接地址在这里呦!!!