Linux之Docker 添加用户认证
Linux之Docker 添加用户认证
私有仓库的TLS加密
以上仓库使用明文的方式,并且没有认证。存在较大的安全隐患,下面介绍使用TLS加密以及用户认证。
为docker仓库添加证书加密功能
docker远程主机访问私有仓库,默认必须使用TLS加密
1 生成证书
[root@toto6 ~]# mkdir -p certs
[root@toto6 ~]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/toto.com.key -x509 -days 365 -out certs/toto.com.crt
Generating a 4096 bit RSA private key
…++
…++
writing new private key to ‘certs/toto.com.key’
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:shaanxi
Locality Name (eg, city) [Default City]:xi’an
Organization Name (eg, company) [Default Company Ltd]:westos
Organizational Unit Name (eg, section) []:docker
Common Name (eg, your name or your server’s hostname) []:toto.com
Email Address []:root@toto.com
[root@toto6 ~]# ls certs/
toto.com.crt toto.com.key # 成功生成证书
1
2、重新启动registry容器:
需要先删除之前开启的容器“
[root@toto6 ~]# docker rm -f registry
registry
重新加密开启容器:
root@toto6 ~]# docker run -d ##-d:打入后台
–restart=always > --name registry \
-v “$(pwd)”/certs:/certs
-v:手动指定数据卷的挂载
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 ##-e:编辑registry的参数;监听443端口
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/toto.com.crt ##使用证书为生成的证书
-e REGISTRY_HTTP_TLS_KEY=/certs/toto,com.key ##使用的私钥
-p 443:443 ##端口映射
registry:2 ##仓库名
查看容器运行情况以及端口开启情况:
[root@toto6 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d3063593b314 registry:2 “/entrypoint.sh /etc…” 33 seconds ago Up 31 seconds 0.0.0.0:443->443/tcp, 5000/tcp registry
[root@toto6 ~]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 656/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 778/master
tcp 0 0 172.25.13.160:22 172.25.13.250:59964 ESTABLISHED 20132/sshd: root@pt
tcp6 0 0 :::22 :: LISTEN 656/sshd
tcp6 0 0 ::1:25 :: LISTEN 778/master
tcp6 0 0 :::443 :: LISTEN 21555/docker-proxy
1
到次registry服务端的TLS加密已经设置好了,但是diocker客户端需要连接这个仓库,也就需要相同的证书才能进行访问。
docker客户端的设置。
设置docker客户端的证书
[root@toto6 ~]# mkdir -p /etc/docker/certs.d/toto.com # 创建该目录,名称和证书域名一致
[root@toto6 ~]# cd /etc/docker/certs.d/toto.com
[root@toto6 toto.com]# cp /root/certs/toto.com.crt ca.crt # 将生成的证书拷贝到该目录中ca.crt
[root@toto6 toto.com]# ls
ca.crt
证书域名解析的更改
[root@toto6 toto.com]# vim /etc/hosts
172.25.13.160 toto6 toto.com
1
2
3 验证部署是否成功
修改本地镜像标签为固定格式:域名/进行名称
[root@toto6 toto.com]# docker tag nginx:v4 toto.com/nginx
1
上传镜像:
[root@toto6 toto.com]# docker push toto.com/nginx
The push refers to repository [toto.com/nginx]
49cb414524e0: Pushed
668afdbd4462: Pushed
latest: digest: sha256:a3e3cbec11f49a4fdebedf975fadbe6dc8cd9e26835fc3018353d7d7f3bdf93b size: 739
作者:若无其事的苹果
来源:CSDN
原文:https://blog.csdn.net/qq_36016375/article/details/96048239
版权声明:本文为博主原创文章,转载请附上博文链接!
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
如何选择阿里云服务器
云计算目前已经成为个人项目和创业公司的首选,上云大大降低了企业的 IT 和运维成本。很多个人和初创公司在选择阿里云服务器的时候,面对复杂的选项和配置时,可能不知道怎么选择。新购用户在选择服务器时,大都希望能够简单、快速、优惠地买对服务器,我想这应该是大部分新用户的诉求。 如何选择阿里云服务器 阿里云 ECS 的购买页面如下,这里我以 1 核 2G 配置为例: 可以看到基础的配置项还是比较多的,需要选择基础的 ECS 规格、镜像、系统等配置。1 核 2G 可选的 ECS 规格有 3 类,分别为:突发性能 t5、共享计算型 n4、共享计算型 n1 这几种规格,简单介绍下这几种 ECS 实例。 突发性能 t5 属于入门级 x86 计算规格族群 处理器:2.5 GHz 主频的 Intel Xeon E5-2682v4 / Intel Xeon(Skylake) Platinum 8163 处理器 搭配 DDR4 内存 适用场景 Web 应用服务器,WordPress、Tomcat 等 轻负载应用、微服务 开发测试压测服务应用 共享计算型 n4 属于入门级 x86 计算规格族群 处理器:2.5 ...
- 下一篇
Linux之Docker私有仓库的搭建
Linux之Docker私有仓库的搭建私有仓库的搭建 下载registry镜像 [root@toto6 images]# docker pull registery:2 [root@toto6 images]# docker images registryREPOSITORY TAG IMAGE ID CREATED SIZEregistry 2 f32a97de94e1 4 months ago 25.8MB= 运行此容器 [root@toto6 images]# docker run -d --name registry -p 5000:5000 -v /opt/registry:/var/lib/registry registry:2 创建并运行容器,设置数据卷,并做端口映射 查看容器运行运行情况以及映射端口开启情况: [root@toto6 images]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESbc3bcd6346f4 registry:2 “/entrypoint.sh /etc…” Ab...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- 设置Eclipse缩进为4个空格,增强代码规范
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- MySQL8.0.19开启GTID主从同步CentOS8
- Hadoop3单机部署,实现最简伪集群
- CentOS8编译安装MySQL8.0.19
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2整合Thymeleaf,官方推荐html解决方案