目录
一、安装Docker
#移除旧依赖,/var/lib/docker/的内容(包括镜像、容器、卷和网络的配置)将被保留
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum install yum-utils
#配置安装包仓库地址,使用阿里云仓库地址(yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#查看新的可安装版本
yum list docker-ce --showduplicates | sort -r
#选择最新版3:20.10.9-3.el7,取中间版本号
yum install docker-ce-20.10.9 docker-ce-cli-20.10.9 containerd.io docker-compose-plugin
#启动docker
systemctl start docker
#验证
docker run hello-world
二、配置远程访问
参考Configure remote access for Docker daemon
通过docker.service
配置
参考Configuring remote access with systemd unit file
#查看docker.service文件位置
systemctl status docker
#docker.service所在目录
cd /usr/lib/systemd/system/
vim docker.service
#修改下列配置
-------------------------------------------------------------
#原配置
[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
#修改为
[Service]
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375 --containerd=/run/containerd/containerd.sock
--------------------------------------------------------------
#重载配置
systemctl daemon-reload
#重启docker服务,下列命令可能无效,执行systemctl stop docker,systemctl stop docker.socket,systemctl start docker
systemctl restart docker.service
#验证
netstat -lntp | grep dockerd
#配置防火墙
firewall-cmd --zone=docker --add-port=2375/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld
#之后便可通过idea等开发工具使用tcp连接
通过daemon.json
文件配置
参考Configuring remote access with daemon.json
修改/etc/docker/daemon.json
cd /etc/docker/
vim daemon.json
-------------------------------------------------------
{
"hosts":["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]
}
-------------------------------------------------------
systemctl daemon-reload
#这种方式重启失败,暂未解决
systemctl restart docker
sudo netstat -lntp | grep dockerd
通过 SSH 证书
参考Use SSH to protect the Docker daemon socket
三、安装Harbor
Harbor是一个开源企业级镜像管理软件
下载安装包
解压安装试运行
上传服务器解压到相应目录
#安装管理工具
yum install docker-compose
#验证
docker-compose --version
#解压安装包
tar -zxvf harbor-offline-installer-v2.7.0.tgz
cd harbor/
#复制一份配置文件
cp harbor.yml.tmpl harbor.yml
--------------------------begin----------------------------
# 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.
# 不能使用lcaohost或者127.0.0.1,这儿使用服务器地址
hostname: 192.168.220.130
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
#自定义端口
port: 18080
#注释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
#ui admin用户密码
harbor_admin_password: Harbor123..
# The default data volume /data
#自定义数据存放位置
data_volume: /usr/local/harbor/data
--------------------------end----------------------------
#配置文件准备
./prepare
#安装
./install.sh
- 输入
192.168.220.130:18080
进行验证
docker配置私有Harbor仓库地址
如果是使用http访问,必须配置--insecure-registry
到/etc/docker/daemon.json
文件中
参考Connecting to Harbor via HTTP
vim /etc/docker/daemon.json
#添加如下内容,若存在daemon.json,则在其中加入 "insecure-registries" : ["192.168.220.130:18080"],
----------------------------------begin-----------------------------------------------------------------
{
"insecure-registries" : ["192.168.220.130:18080"]
}
----------------------------------end-----------------------------------------------------------------
#停止docker实例,进入相应的软件目录,即/usr/local/harbor
docker-compose down -v
#重新加载配置文件
systemctl daemon-reload
#重启docker服务
systemctl stop docker
systemctl start docker
#重启docker实例
docker-compose up -d
- 测试推送镜像
使用hello-world测试
docker images
docker ps -f id=06656f24df5a -a
#创造新的镜像
#commit 针对容器,06656f24df5a容器id
docker commit -a "gw" -m "测试harbor仓库" 06656f24df5a hello-world:v1.1.0
docker commit -a "gw" -m "测试harbor仓库" 06656f24df5a 192.168.220.130:18080/tlop-dev/hello-world:v1.2.0
#登录harbor镜像仓库
docker login --username=admin 192.168.220.130:18080
#将刚刚提交的镜像推送到harbor仓库
#tar 针对镜像afdaa8c4f8ca为镜像id
docker tag hello-world:v1.1.0 192.168.220.130:18080/tlop-dev/hello-world:v1.1.0
#推送到harbor私有仓库
docker push 192.168.220.130:18080/tlop-dev/hello-world:v1.1.0
****未推送时
**** 推送后
- 测试拉取镜像
#删除本地镜像
docker rmi 192.168.220.130:18080/tlop-dev/hello-world:v1.1.0
#拉取镜像
docker pull 192.168.220.130:18080/tlop-dev/hello-world:v1.1.0
#查看
docker images
Idea 连接Harbor
- 配置仓库地址
- idea推送至Harbor
**** 点击需要推送的镜像,修改标签
**** 在新标签的镜像上点击推送图标
**** 推送成功
问题解决
- -bash: docker-compose: command not found
yum install docker-compose
docker-compose --version
- Stopping docker.service, but it can still be activated by: docker.socket
systemctl stop docker
#再次执行
systemctl stop docker.socket
标签:daemon,harbor,Harbor,--,systemctl,Linux,Docker,安装,docker
From: https://www.cnblogs.com/jinit/p/17002787.html