docker pull centos7的CentOS的镜像的root密码是多少

Docker 定制容器镜像的2种方法_服务器应用_Linux公社-Linux系统门户网站
你好,游客
Docker 定制容器镜像的2种方法
作者:飞走不可
  由于在测试环境中使用了Docker官网的 镜像,但是该镜像里面默认没有安装ssh服务,在做测试时又需要开启ssh。所以上网也查了查资料。下面详细的纪录下。在CentOS 容器内安装ssh后,转成新的镜像用于后期测试使用。
二、镜像定制
第一种方式(手动修改容器镜像)
1.先下载centos镜像
[root@docker ~]# docker pull centos
2.启动容器并进行配置
启动容器,
[root@docker ~]# docker run -it -d --name test-centos1 centos
d72250ecaa5e3e36226a1edd749f494d9f00eddc65aa4e551791a
命令注释:-it : 进行交互式操作
     -d : 等同于 -d=true,容器将会在后台运行,不然执行一次命令后,退出后,便是exit状态了。
     --name : 容器启动后的名字,默认不指定,将会随机产生一个名字。或者使用 -name="containers_name"&
     centos:使用的镜像名称
进入容器,安装ssh server,以及配置开机启动
[root@docker ~]# docker exec -it test-centos1 /bin/bash
[root@d72250ecaa5e /]# ifconfig
bash: ifconfig: command not found
注:命令最后参数 /bin/bash: 指进入容器时执行的命令(command)
我们检查了下容器,暂时安装以下必用的软件吧 net-tools,openssh-server
[root@d72250ecaa5e /]# yum install openssh-server net-tools -y
创建ssh 所需的目录,并在根目录创建sshd 启动脚本
[root@d72250ecaa5e /]# mkdir -pv /var/run/sshd
mkdir: created directory '/var/run/sshd'
[root@d72250ecaa5e /]# cat /auto_sshd.sh
#!/bin/bash
/usr/sbin/sshd -D
[root@d72250ecaa5e /]# chmod +x /auto_sshd.sh
修改容器内root 的账户密码
[root@d72250ecaa5e /]# echo "root:iloveworld" | chpasswd
生成ssh 主机dsa 密钥(不然ssh 该容器时,会出现错误。)
[root@d72250ecaa5e /]# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
[root@d72250ecaa5e /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
我们加一个history记录的时间功能吧,这样方便后期查看
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' && /etc/profile
OK,配置基本完毕咯。清理命令历史纪录,之后退出容器。现在可以生成一个新的docker 镜像了。
3.配置完成后,进行打包成新的镜像
[root@docker ~]# docker commit test-centos1 centos_sshd:7.0
sha256:6e3330b30dfff5f029fcfffffbc37dcf2a4ebfbc944d
[root@docker ~]# docker images
REPOSITORY
centos_sshd
6e3330b30dff
8 seconds ago
docker.io/
12 days ago
命令注释:commit: 提交一个具有新配置的容器成为镜像,后面跟容器的name 或者容器Id ,最后是生成新镜像的名字
更新:这条命令更方便以后启动,如下:
[root@docker ~]# docker commit --change='CMD ["/auto_sshd.sh"]' -c "EXPOSE 22" test-centos1 centos_sshd:7.0
sha256:7bb4efd82c4ff1f241cbc57ee45aab1b05d214b1e9fcdd480e70b
命令注释: --change : 将后期使用此镜像运行容器时的命令参数、开放的容器端口提前设置好。
更多Docker相关教程见以下内容:&
Docker安装应用(CentOS 6.5_x64) &
Ubuntu 14.04安装Docker& &
Ubuntu使用VNC运行基于Docker的桌面系统& &
阿里云CentOS 6.5 模板上安装 Docker &
Ubuntu 15.04下安装Docker& &
在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker &
在 Ubuntu 15.04 上如何安装Docker及基本用法 &
Docker快速入门基础教程&
查看镜像,并启动新的容器
[root@docker ~]# docker images
REPOSITORY
centos_sshd
7bb4efd82c4f
4 minutes ago
docker.io/ubuntu
12 days ago
[root@docker ~]# docker run -d -it --name centos_7.0-1 centos_sshd:7.0
ec17e553d5c4c60865afeb99df8dfd1f4e7d4ba6e1b0dd1d6356
[root@docker ~]# docker ps -a
CONTAINER ID
ec17e553d5c4
centos_sshd:7.0
"/auto_sshd.sh"
6 seconds ago
Up 5 seconds
centos_7.0-1
进行ssh测试,先查看一下该容器的ip,之后ssh。ok
[root@docker ~]# docker exec centos_7.0-1 hostname -i
172.17.0.4
[root@docker ~]# ssh root@172.17.0.4
The authenticity of host '172.17.0.4 (172.17.0.4)' can't be established.
RSA key fingerprint is 87:88:07:12:ac:0a:90:28:10:e1:9e:eb:1f:d6:c9:9d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.4' (RSA) to the list of known hosts.
root@172.17.0.4's password:
Last login: Tue Nov 29 16:00:49 2016 from gateway
[root@ec17e553d5c4 ~]# w
16:34:17 up 63 days,
load average: 0.00, 0.02, 0.05
[root@ec17e553d5c4 ~]# ping gateway
PING gateway (172.17.0.1) 56(84) bytes of data.
64 bytes from gateway (172.17.0.1): icmp_seq=1 ttl=64 time=0.048 ms&
更多详情见请继续阅读下一页的精彩内容:
相关资讯 & & &
& (昨 09:18)
& (01月27日)
& (昨 09:21)
& (02月11日)
& (01月03日)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款教你怎么半天搞定Docker - 推酷
教你怎么半天搞定Docker
首先,不要把docker想的那么高大,它不就是先做个镜像,然后通过docker像虚拟机一样跑起来嘛...docker其实在真实业务场景中还是非常有局限性的。Dockerfile脚本也没那么好写,有些应用也没有那么好安装。
废话不多说,教你半天搞定docker!
自己去下载相应版本,不建议使用yum,提倡版本一致性。
docker-engine-1.7.1-1.el6.x86_64.rpm
epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
rpm -ivh docker-engine-1.7.1-1.el6.x86_64.rpm
启动docker
service docker start
搜索公开容器镜像
docker search centos6.6
支持模糊搜索,但不要想着公开的容器有多好,适合公司业务的还是需要自己搭建。
DESCRIPTION
liangtong/centos6.6-httpd
incu6us/centos6.6-with-nginx
Wav server for FreeCall
eliezio/centos6.6-devtoolset2-gtest
Docker image based on Centos 6.6 suitable ...
chrisgeorge/centos6.6-py2.6
CentOS 6.6 with Python 2.6
leonion/centos6.6
heilee/centos6.6
karthi12345/centos6.6
kalramain/centos6.6-mysql55
mysql5.5 installed on centos6.6
加载镜像容器
docker pull chrisgeorge/centos6.6-py2.6&NAME&
docker run -i -t chrisgeorge/centos6.6-py2.6 /bin/bash
这样就交互登录到你预先设计好的容器里面去了
yum install openssh-server
需要修改/etc/ssh/sshd_config文件中内容
PermitRootLogin yes
ssh-keygen -q -N && -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -q -N && -t rsa -f /etc/ssh/ssh_host_rsa_key
mkdir /var/run/sshd
passwd 登录密码
/etc/init.d/sshd start
docker commit ID &name&
docker rmi &neme&
docker rmi -f
docker run -d -p 22 -p
chrisgeorge/centos6.6-py2.6 /usr/sbin/sshd -D
将容器8000端口映射到docker服务器8022端口,将容器22端口随机映射端口
docker save chrisgeorge/centos6.6-py2.6 &/root/docker-pmd.tar
docker load & /root/docker-pmd.tar
想跑起来镜像,就必须每台机子装有docker。
Dockerfile
脚本:/home/docker/Dockerfile
FROM chrisgeorge/centos6.6-py2.6 #继承的父容器
MAINTAINER wonter #作者
RUN yum install nginx #在新的容器里安装nginx
RUN echo &root:root& | chpasswd #设置密码
EXPOSE 22 #设置端口
CMD /etc/init.d/nginx start #启动服务
docker build -t wonter .
#删除docker历史容器
docker ps -a -q | xargs docker rm
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致1533人阅读
Docker(4)
Docker 镜像及Docker仓库配置 [四]
标签(空格分隔): Docker
时间:日15:45:20
微信公众号:abcdocker
Abcdocker交流群:
如果遇到什么问题可以进群询问,我们是一个乐于帮助的集体!**
一、Docker 镜像介绍
Docker镜像构建分为两种,一种是手动构建,另一种是Dockerfile(自动构建)
Docker镜像手动构建案例:
我们基于centos镜像进行构建,制作nginx镜像
[root@linux-node1 ~]# docker run --name abcdocker -it centos
[root@026ae321431d /]# yum install wget -y
[root@026ae321431d /]# wget -O /etc/yum.repos.d/epel.repo /repo/epel-7.repo
[root@026ae321431d /]# yum install nginx -y
我们需要修改nginx配置文件,让他运行在前台
[root@026ae321431d /]# vi /etc/nginx/nginx.conf
修改完之后我们退出
[root@linux-node1 ~]# docker ps -a
CONTAINER ID
026ae321431d
"/bin/bash"
8 minutes ago
Exited (0) 4 seconds ago
我们修改完之后需要commit
[root@linux-node1 ~]# docker commit -m "My Nginx" 026ae321431d abcdocker/abcdocker:v1
sha256:d1da04e088afa5bc005fbef9c75c6c4dfdda2ca82f4
[root@linux-node1 ~]# docker images
REPOSITORY
abcdocker/abcdocker
d1da04e088af
4 minutes ago
docker.io/nginx
e43d811ce2f4
34 hours ago
docker.io/centos
980e0e4c79ec
6 weeks ago
第一个abcdocker是仓库的名称
第二个abcdocker是镜像的名称
v1 标签,如果是最后一个版本我们可以打latest
我们现在启动制作好的nginx镜像
[root@linux-node1 ~]# docker run --name nginxv1 -d -p 81:80 abcdocker/abcdocker:v1 nginx
2827b5ff8a1e094b4cc23a075bda90fabff1c671e
我们要写镜像全称,带上标签
提示:后面的nginx不是镜像的nginx,而是服务的名称
我们可以查看访问日志
[root@linux-node1 ~]# ./docker_in.sh nginxv1
[root@36 /]# tail -f /var/log/nginx/access.log
192.168.56.1 - - [23/Oct/2016:09:09:49 +0000] "GET / HTTP/1.1" 200 3700 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/ Firefox/49.0" "-"
192.168.56.1 - - [23/Oct/2016:09:09:49 +0000] "GET /nginx-logo.png HTTP/1.1" 200 368 "http://192.168.56.11:81/" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/ Firefox/49.0" "-"
192.168.56.1 - - [23/Oct/2016:09:09:49 +0000] "GET /poweredby.png HTTP/1.1" 200 2811 "http://192.168.56.11:81/" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/ Firefox/49.0" "-"
192.168.56.1 - - [23/Oct/2016:09:09:49 +0000] "GET /favicon.ico HTTP/1.1" 404 3650 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/ Firefox/49.0" "-"
192.168.56.1 - - [23/Oct/2016:09:09:49 +0000] "GET /favicon.ico HTTP/1.1" 404 3650 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/ Firefox/49.0" "-"
以上就是手动构建nginx镜像
Dockerfile是由一行命令和语句组成的
Dockerfile构建步骤:
[root@linux-node1 ~]# mkdir /dockerfile
[root@linux-node1 ~]# cd /dockerfile
[root@linux-node1 dockerfile]#
[root@linux-node1 dockerfile]# mkdir nginx
[root@linux-node1 dockerfile]# cd nginx/
[root@linux-node1 nginx]#
我们要在nginx目录上自动化创建一个nginx镜像
注意:D需要大写,当我们构建dockerfile的时候,docker默认会在我们当前目录读取一个名为Dockerfile的文件。这时候的D必须大写
[root@linux-node1 nginx]# cat Dockerfile
FROM centos
MAINTAINER abcdocker xxx@
RUN rpm -ivh /epel/epel-release-latest-7.noarch.rpm
RUN yum install -y nginx && yum clean all
RUN echo "" &&/etc/nginx/nginx.conf
ADD index.html /usr/share/nginx/html/index.html
CMD ["nginx"]
#井号代表注释
#Base image
除了注释的第一行,必须是FROM,意思就是我们需要告诉dockerfile基础镜像是什么
#Maintainer 维护信息
#Commands 命令
#ADD index.html 这个文件需要我们在当前目录下有才可以,我们配置我们可以准备好,然后使用ADD命令进行添加或修改
EXPOSE 对外端口号
CMD [“nginx”] 它要启动的命令是nginx (就算是nginx服务)
关于Dokcerfile文章:
我们写好dockerfile还需要一个index.html
[root@linux-node1 nginx]# echo
&index.html
[root@linux-node1 nginx]# ll
-rw-r--r-- 1 root root 368 Oct 23 18:04 Dockerfile
-rw-r--r-- 1 root root
18 Oct 23 18:06 index.html
提示:.代表构建的位置,我们是当前目录,我们使用docker build进行构建
[root@linux-node1 nginx]# docker build -t mynginx:v2 .
构建完成后我们就知道我们配置的都是那些
[root@linux-node1 nginx]# docker images
REPOSITORY
0d327c3d5058
8 minutes ago
abcdocker/abcdocker
d1da04e088af
About an hour ago
docker.io/nginx
e43d811ce2f4
35 hours ago
docker.io/centos
980e0e4c79ec
6 weeks ago
[root@linux-node1 nginx]# docker run --name mynginxtest -d -p 82:80 mynginx:v2
71ca33feff85f948cc5e3ccf6cda123520
Dockerfile参数解释
FROM 指定基础镜像
MAINTAINER 指定维护者信息
RUN 在命令前面加上RUN
ADD COPY文件,会自动解压
WORKDIR 设置当前工作目录,类似于cd
VOLUME 设置卷,挂载主机目录
EXPOSE 指定对外的端口
CMD 指定容器启动后要干的事情
Dockerfile文章:
二、Docker仓库
 Docker的仓库是DockerHub,类似于github,github有一个开源的软件叫gitlab。Docker也有一个开源软件docker registry
 我们先查看镜像,找到registry
[root@linux-node1 ~]# docker search docker
DESCRIPTION
docker.io/jenkins
Official Jenkins Docker image
docker.io/alpine
A minimal Docker image based on Alpine Lin...
docker.io/registry
Containerized docker registry
docker.io/swarm
Swarm: a Docker-native clustering system.
docker.io/fedora
Official Docker builds of Fedora
docker.io/docker
Docker in Docker!
docker.io/konradkleine/docker-registry-frontend
Browse and modify your Docker registry in ...
docker.io/oddrationale/docker-shadowsocks
shadowsocks Docker image
docker.io/docker-dev
Docker is an open source project to pack, ...
docker.io/hyper/docker-registry-web
Web UI, authentication service and event r...
docker.io/datadog/docker-dd-agent
Docker container for the Datadog Agent.
docker.io/francescou/docker-compose-ui
web interface for Docker Compose
docker.io/nodered/node-red-docker
Node-RED Docker images.
docker.io/spotify/docker-gc
Garbage collection of Docker containers an...
docker.io/devalx/docker-teamspeak3
Docker Container with Teamspeak 3. Contain...
docker.io/grahamdumpleton/mod-wsgi-docker
Docker images for Apache/mod_wsgi.
docker.io/dockercore/docker
docker.io/docker/docker-bench-security
Docker Bench checks for dozens of common b...
docker.io/laurentmalvert/docker-boinc
A dockerized BOINC client
docker.io/rubinius/docker
Docker images for Rubinius and other parts...
docker.io/docker/migrator
Tool to migrate Docker images from a v1 re...
docker.io/fabric8/jenkins-docker
Fabric8 Jenkins Docker Image
docker.io/jakubsacha/symfony-docker
Docker image tailed to run symfony applica...
docker.io/cgal/testsuite-docker
Docker images for the CGAL testsuite
docker.io/jfisbein/docker-images
Various Docker build files for creating Do...
我们可以通过docker pull 来下载一个
[root@linux-node1 ~]
[root@linux-node1 ~]# docker images
REPOSITORY
0d327c3d5058
26 hours ago
abcdocker/abcdocker
d1da04e088af
27 hours ago
docker.io/nginx
e43d811ce2f4
2 days ago
docker.io/registry
c9bd19d022f6
5 days ago
docker.io/centos
980e0e4c79ec
6 weeks ago
docker.io/vmware/admiral
4e798983bb2a
6 weeks ago
默认占用5000端口,我们查看是否存在5000端口
[root@linux-node1 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address
Foreign Address
PID/Program name
0 0.0.0.0:3306
19995/mysqld
0 0.0.0.0:4369
21574/epmd
0 0.0.0.0:22
0 0.0.0.0:15672
21557/beam
0 127.0.0.1:25
1372/master
0 0.0.0.0:25672
21557/beam
119979/docker-proxy
21574/epmd
122045/docker-proxy
1372/master
7571/docker-proxy
21557/beam
0 0.0.0.0:123
19389/chronyd
0 127.0.0.1:323
19389/chronyd
19389/chronyd
我们开始运行容器
[root@linux-node1 ~]# docker run -d -p
aa6b8ce82d5abaa8bca5ccb8caba769d964
提示:docker比较老的版本运行起来就可以运行,1.7之后都不可以
我们新打一个标签
[root@linux-node1 ~]# docker tag abcdocker/abcdocker:v1 192.168.56.11:5000/abc/mynginx:latest
因为Docker从1.3.X之后默认docker registry使用的是https,所以当用docker pull命令下载远程镜像时,如果远程docker registry是非https的时候就会报上面的错误。
[root@linux-node1 ~]# docker tag abcdocker/abcdocker:v1 192.168.56.11:5000/abc/mynginx:latest
[root@linux-node1 ~]# docker push 192.168.56.11:5000/abc/mynginx:latest
The push refers to a repository [192.168.56.11:5000/abc/mynginx]
unable to ping registry endpoint https://192.168.56.11:5000/v0/
v2 ping attempt failed with error: Get https://192.168.56.11:5000/v2/: http: server gave HTTP response to HTTPS client
v1 ping attempt failed with error: Get https://192.168.56.11:5000/v1/_ping: http: server gave HTTP response to HTTPS client
提示:解决方法有2种,一种是去沃通或腾讯申请免费ssl,或者我们本地修改配置文件
解决Https问题
安装nginx,制作https
[root@linux-node1 ~]# yum install nginx -y
[root@linux-node1 ~]# vim /etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.
因为在配置文件中已经指定了目录,只有放在/etc/nginx/conf.d/*下面才会识别到
配置如下:
[root@linux-node1 conf.d]# cat docker.conf
upstream docker-registry {
server 127.0.0.1:5000;
listen 443;
server_name
ssl_certificate
/etc/ssl/nginx.
ssl_certificate_key /etc/ssl/nginx.
proxy_set_header Host
proxy_set_header X-Real-IP $remote_
client_max_body_size 0;
chunked_transfer_
location / {
auth_basic
auth_basic_user_file
/etc/nginx/conf.d/docker-registry.
proxy_pass http://docker-
location /_ping {
proxy_pass http://docker-
location /v1/_ping {
proxy_pass http://docker-
[root@linux-node1 conf.d]#
我们需要生成一个证书,大家可以申请一个沃通或者腾讯的免费ssl
以下如果有沃通的免费ssl就不需要设置
我们先设置一个根密钥,生产上直接使用沃通的免费ssl配置就可以了
---------------此步在生产可以不使用--------------------
[root@linux-node1 ~]# cd /etc/pki/CA/
[root@linux-node1 CA]# touch ./{serial,index.txt}
[root@linux-node1 CA]# echo "00" &serial
[root@linux-node1 CA]# openssl genrsa -out private/cakey.pem 2048
Generating RSA private key, 2048 bit long modulus
.................................+++
............+++
e is 65537 (0x10001)
[root@linux-node1 CA]# openssl req -new -x509 -key private/cakey.pem -days 3650 -out cacert.pem
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) []: 输入BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:abcdocker
Organizational Unit Name (eg, section) []:docker
Common Name (eg, your name or your server's hostname) []:
Email Address []:
以上步骤是生成一个根证书
我们现在需要生产一个nginx的证书(生产可以直接使用运营商颁发的证书,不需要生成)
[root@linux-node1 CA]# cd /etc/ssl/
[root@linux-node1 ssl]# openssl genrsa -out nginx.key 2048
Generating RSA private key, 2048 bit long modulus
.........................................+++
[root@linux-node1 ssl]# openssl req -new -key nginx.key -out nginx.csr
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) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:abcdocker
Organizational Unit Name (eg, section) []:docker
Common Name (eg, your name or your server's hostname) []:
Email Address []:cyh@
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@linux-node1 ssl]# openssl ca -in nginx.csr -days 365 -out nginx.crt
Using configuration from /etc/pki/f
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 0 (0x0)
Not Before: Oct 24 14:04:16 2016 GMT
Not After : Oct 24 14:04:16 2017 GMT
countryName
stateOrProvinceName
organizationName
= abcdocker
organizationalUnitName
commonName
emailAddress
X509v3 extensions:
X509v3 Basic Constraints:
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
29:04:19:D9:1A:C1:8C:1C:11:38:FF:75:85:1F:B2:BD:E1:1C:79:5C
X509v3 Authority Key Identifier:
keyid:70:D7:95:49:C3:40:05:43:43:D4:07:AE:4D:AB:F2:D6:40:28:63:8D
Certificate is to be certified until Oct 24 14:04:16 2017 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n] y
CERTIFICATION CANCELED
因为我们设置的是自签证书,要让系统允许
[root@linux-node1 ~]# cat /etc/pki/CA/cacert.pem && /etc/pki/tls/certs/ca-bundle.crt
我们创建一个用来验证的账号密码
[root@linux-node1 ~]# htpasswd -c /etc/nginx/conf.d/docker-registry.htpasswd abcdocker
New password:
Re-type new password:
Adding password for user abcdocker
[root@linux-node1 ~]# systemctl start nginx
查看是否有443端口
[root@linux-node1 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address
Foreign Address
PID/Program name
0 0.0.0.0:3306
19995/mysqld
0 0.0.0.0:80
14408/nginx: master
0 0.0.0.0:4369
21574/epmd
0 0.0.0.0:22
0 0.0.0.0:15672
21557/beam
0 127.0.0.1:25
1372/master
0 0.0.0.0:443
14408/nginx: master
0 0.0.0.0:25672
21557/beam
14408/nginx: master
119979/docker-proxy
21574/epmd
122045/docker-proxy
1372/master
7571/docker-proxy
12308/docker-proxy
21557/beam
0 0.0.0.0:123
19389/chronyd
0 127.0.0.1:323
19389/chronyd
19389/chronyd
我们还需要做一个绑定,设置host解析
[root@linux-node1 ~]# cat /etc/hosts
localhost localhost.localdomain localhost4 localhost4.localdomain4
localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.11 linux-
192.168.56.12 linux-
修改配置文件
[root@linux-node1 ~]# vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 192.168.56.11:5000'
[root@linux-node1 ~]# docker push 192.168.56.11:5000/abcdocker/abcnginx:latest
The push refers to a repository [192.168.56.11:5000/abcdocker/abcnginx]
f69e85c4fed0: Pushed
0aeb287b1ba9: Pushed
latest: digest: sha256:516af657a984c19c3e1a4cc90fff99cf065d5b1e5f0796 size: 719
小结:制作好nginx—ssl 后,docker基本上只需要三步
1、修改/etc/sysconfig/docker 配置文件,设置域名
2、构建镜像
[root@linux-node1 ~]# docker tag abcdocker/abcdocker:v1 192.168.56.11:5000/abcdocker/abc:latest
3、上传到仓库中
[root@linux-node1 ~]# docker push 192.168.56.11:5000/abcdocker/abc:latest
提示:如果使用的是域名此处的IP地址就是域名的地址
首先我们修改配置文件,因为不是https,所以要修改配置文件,跟服务端修改的一样
设置hosts解析
然后我们使用docker pull即可
[root@linux-node2 ~]
REPOSITORY
[root@linux-node2 ~]
Trying to pull repository 192.168.56.11:5000/abcdocker/abc ...
latest: Pulling from 192.168.56.11:5000/abcdocker/abc
8d30e94188e7: Pull complete
9cc6fcb823f4: Pull complete
Digest: sha256:516af657a984c19c3e1a4cc90fff99cf065d5b1e5f0796
Status: Downloaded newer image for 192.168.56.11:5000/abcdocker/abc:latest
查看是否存在
[root@linux-node2 ~]# docker images
REPOSITORY
192.168.56.11:5000/abcdocker/abc
d1da04e088af
44 minutes ago
[root@linux-node2 ~]# docker run -d -it --name nginx1 -d -p 81:80 192.168.56.11:5000/abcdocker/abc
5086eafe42a7c82c8c1b2adaeaaec349c407d57868add9cd7a77e
[root@linux-node2 ~]# sh docker.sh nginx1
[root@5086eafe42a7 /]# ls
anaconda-post.log
lost+found
案例:按照我们上面的方法,制作一个nginx镜像并上传到docker仓库中,并运行容器启动nginx服务
[root@linux-node2 ~]# docker run -d
--name nginx -p 192.168.56.12:87:80 192.168.56.11:5000/abc
477a9eda45b539698efc0eedc580d123fdf3205bfd445
[root@linux-node2 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address
Foreign Address
PID/Program name
0 0.0.0.0:22
0 192.168.56.12:87
25508/docker-proxy
0 127.0.0.1:25
1373/master
1373/master
Docker仓库含义
  我们制作好镜像后,默认存放在本地,只可以我们本机使用,其他服务器无法使用,这时候就需要我们一个docker仓库,其他服务器使用的时候只需要进行pull下来即可
 Docker默认提供了一个仓库叫docker registry
 Docker registry需要使用https进行验证
Docker registry私有仓库搭建基本几步流程(采用nginx+认证的方式)
申请免费的ssl证书 /free
设置nginx ssl证书
proxy_pass 5000
docker run -d -p
–name registry registry:2
docker registry可能比较low,我们还可以使用harbor是由VMware写的一款针对企业级的开源软件
下载链接:
中文文档:
Harbor简介
  Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。
基于角色的访问控制 - 用户与Docker镜像仓库通过“项目”进行组织管理,一个用户可以对多个镜像仓库在同一命名空间(project)里有不同的权限。
镜像复制 - 镜像可以在多个Registry实例中复制(同步)。尤其适合于负载均衡,高可用,混合云和多云的场景。
图形化用户界面 - 用户可以通过浏览器来浏览,检索当前Docker镜像仓库,管理项目和命名空间。
AD/LDAP 支持 - Harbor可以集成企业内部已有的AD/LDAP,用于鉴权认证管理。
审计管理 - 所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。
国际化 - 已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言会添加进来。
RESTful API - RESTful API 提供给管理员对于Harbor更多的操控, 使得与其它管理软件集成变得更容易。
部署简单 - docker-compose和离线安装。
VMware 一共有3个开源项目
admiral Docker web管理界面
但是adminiral和harbor虽然都是VMware的开源软件,但是admiral没有harbor好用
     更多精彩请继续关注我们!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:21410次
排名:千里之外
原创:34篇
个人博客地址:
(1)(4)(1)(4)(23)(2)(1)

我要回帖

更多关于 docker pull 阿里镜像 的文章

 

随机推荐