Docker初学者入门--安装笔记( 二 )


Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
[root@promote ~]#
------------------------------------------------------以上安装完成,以下为操作:------------------------------------
七:操作Helloworld.
理论上应该从https://hub.docker.com上拉镜像,但速度太慢,所以用国内的镜像加速版 。
阿里云镜像加速器步骤:
1,是什么 https://dev.aliyun.com/search.html(转到:https://promotion.aliyun.com/ntms/act/kubernetes.html)
a,注册一个属于自己的阿里云账户(可复用淘宝账号)
b, 获得加速器地址连接 (登陆阿里云开发者平台后获取加速器地址)
在容器镜像服务-->快速入门-->官方镜像加速---> 点击“容器镜像服务控制台”-->前往开通 。
(容器镜像服务控制台后左侧的加速器帮助页面就会显示为您独立分配的加速地址):
 
到了“容器镜像服务”后,右边会有一个“设置Registry登录密码”,(设置为:admin****(需要自定义))
找到镜像中心---> 镜像加速器-->CentOS, 看到我的加速器地址为:https://z2jkh8aj.mirror.aliyuncs.com
c,配置本机Docker运行镜像加速器
cat /etc/sysconfig/docker
vi /etc/sysconfig/docker 在other_args="" 上修改,内容如下:
------------------------
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d
other_args="--registry-mirror=https://z2jkh8aj.mirror.aliyuncs.com"
DOCKER_CERT_PATH=/etc/docker
# Resolves:
DOCKER_NOWARN_KERNEL_VERSION=1
---------------------
wq保存,重启docker.
d,重新启动Docker后台服务:service docker restart
e, Linux系统下配置完加速器需要检查是否生效,
命令为: ps -ef|grep docker
[root@promote ~]# ps -ef|grep docker
root 27217 1 4 06:44 pts/0 00:00:03 /usr/bin/docker -d --registry-mirror=https://z2jkh8aj.mirror.aliyuncs.com
root 27267 26600 0 06:45 pts/0 00:00:00 grep docker
八、演示HelloWorld:
 
1, docker run hello-world:
[root@promote ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally ---- 表示本地没有,要从阿里云上下载一个hello-world的镜像,并在容器内运行
latest: Pulling from hello-world
65b27d3bd74d: Pull complete
9f5834b25059: Pull complete
Digest: sha256:fb158b7ad66f4d58aa66c4455858230cd2eab4cdf29b13e5c3628a6bfc2e9f05 (ID号)
Status: Downloaded newer image for hello-world:latest
Hello from Docker! ------表示拉取成功 。
This message shows that your installation appears to be working correctly.
...............
输出以上提示后,hello world 就会停止运行,容器自动终止 。
如果云上也没有所需的镜像,会给出错误提示 。
九、 Docker常用命令:
1,帮助命令:
docker version, docker info , docker --help(查看各种命令)*****
 
2, 镜像命令:
 
(1) docker images: 列出本地主机上的镜像
 
REPOSITORY :表示镜像的仓库源 TAG: 镜像的标签
IMAGE ID: 镜像ID CREATED:镜像的创建时间 VIRTUAL SIZE: 镜像大小
同一仓库源可以有多个TAG,代表这个仓库源的不同个版本,我们使用REPOSITORY:TAG来定义不同的镜像 。
如果你不指定一个镜像的版本标签,例如你只使用ubuntu,docker将默认使用ubuntu:latest镜像
options说明:
-a :列出本地所有的镜像(含中间映像层(如里面的none等....));
-q: 只显示镜像ID; (或-qa)
--digests: 显示镜像的摘要信息; --no-trunc: 显示完整的镜像信息 。
(2) docker search [OPTIONS] 某个镜像的名字,(http://hub.docker.com)查询的时候,是从hub.docker.com上查,拉取的时候可以从上面配置的阿里云上下 。例: 命令:docker search Tomcat
OPTIONS说明: --no-trunc: 显示完整的镜像描述; -s: 列出收藏数不小于指定值的镜像;(***** 一般用点赞数多的)
--automated: 只列出automated build 类型的镜像
docker search -s 30 tomcat : 查询出点赞数超过30的tomcat. ( docker search -s 30 --no-trunc tomcat )
 
(3) docker pull: 下载镜像
例: docker pull tomcat 等价于 docker pull tomcat:lastest (:lastest 可省略) (docker pull tomcat:5.9 ---表示拉取tomcat 5.9版本)


推荐阅读