牛刀小试之docker安装部署

安装

[root@docker-master yum.repos.d]#  curl https://git.oschina.net/feedao/Docker_shell/raw/start/ali-centos.sh | sh
[root@docker-master yum.repos.d]#  yum install docker-io

启动

[root@docker-master yum.repos.d]# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:                                        [  OK  ]
[root@docker-master yum.repos.d]# chkconfig --level 35 docker on
[root@docker-master yum.repos.d]#

查看版本

[root@test-devops mysql]#
[root@test-devops mysql]# docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.3.3
Git commit (client): a8a31ef/1.5.0
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.3.3
Git commit (server): a8a31ef/1.5.0
[root@test-devops mysql]#

使用docker获取镜像

[root@docker-master ~]# docker pull ubuntu:12.04
Pulling repository ubuntu
28a945b4333c: Pulling image (12.04) from ubuntu, endpoint: https://registry-1.docker.io/v128a945b4333c: Download complete
511136ea3c5a: Download complete
a0ab785b06af: Download complete
db7c9bd0e843: Download complete
14500324c585: Download complete
Status: Downloaded newer image for ubuntu:12.04
[root@docker-master ~]#

也可以如下方式安装:

[root@docker-master ~]# docker pull dl.dockerpool.com:5000/ubuntu:12.04

下载完成之后使用镜像创建容器:

[root@docker-master ~]# docker run -t -i ubuntu:12.04 /bin/bash
root@a38b24272f39:/# pwd
/
root@a38b24272f39:/# hostname
a38b24272f39
root@a38b24272f39:/#
-t 是指分派一个伪终端
-i 是让容器标准输出打开

列出本地镜像:

[root@docker-master ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               28a945b4333c        3 days ago          130.3 MB
ubuntu              12.04.5             28a945b4333c        3 days ago          130.3 MB
ubuntu              precise             28a945b4333c        3 days ago          130.3 MB
[root@docker-master ~]#


REPOSITORY  来自哪个仓库
TAG                   标签
ImageID             唯一ID
Created              创建时间
Size                   镜像大小

新建使用:

[root@docker-master test]# docker run ubuntu:12.04 /bin/echo "hello world"
hello world
[root@docker-master test]#

导出导入容器:

#查看 ID

[root@docker-master ~]# docker ps a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
7582b0eaf376        ubuntu:latest       "/bin/bash"         12 minutes ago      Up 12 minutes                           desperate_feynman
268b9fc77889        ubuntu:12.04        "/bin/bash"         29 minutes ago      Up 29 minutes                           tender_galileo

#备份id镜像

[root@docker-master ~]# docker export 7582b0eaf376 > ubuntu.tar
[root@docker-master ~]# cat ubuntu.tar | docker import - test/buntu:v1.0
bcbf83ff7331f3a222a0c18a94379ab7e95aea60202751ccd5c1ab651528cb85

#导入备份ID

[root@docker-master ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
test/buntu          v1.0                bcbf83ff7331        30 seconds ago      192.5 MB
<none>              <none>              3039b31f25fe        3 hours ago         222 MB
ubuntu              precise             28a945b4333c        4 days ago          130.3 MB
ubuntu              12.04               28a945b4333c        4 days ago          130.3 MB
ubuntu              12.04.5             28a945b4333c        4 days ago          130.3 MB
ubuntu              latest              04c5d3b7b065        2 weeks ago         192.7 MB
centos              centos6             25c5298b1a36        4 weeks ago         215.8 MB
jpetazzo/nsenter    latest              6ed3da1d7fa6        5 weeks ago         367.7 MB
[root@docker-master ~]#

删除images

[root@docker-master ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
test/buntu          v1.0                bcbf83ff7331        19 minutes ago      192.5 MB
<none>              <none>              3039b31f25fe        4 hours ago         222 MB
ubuntu              12.04               28a945b4333c        4 days ago          130.3 MB
ubuntu              12.04.5             28a945b4333c        4 days ago          130.3 MB
ubuntu              precise             28a945b4333c        4 days ago          130.3 MB
ubuntu              latest              04c5d3b7b065        2 weeks ago         192.7 MB
centos              centos6             25c5298b1a36        4 weeks ago         215.8 MB
jpetazzo/nsenter    latest              6ed3da1d7fa6        5 weeks ago         367.7 MB
[root@docker-master ~]# docker rmi test/buntu:v1.0
Untagged: test/buntu:v1.0
Deleted: bcbf83ff7331f3a222a0c18a94379ab7e95aea60202751ccd5c1ab651528cb85
[root@docker-master ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              3039b31f25fe        4 hours ago         222 MB
ubuntu              12.04.5             28a945b4333c        4 days ago          130.3 MB
ubuntu              precise             28a945b4333c        4 days ago          130.3 MB
ubuntu              12.04               28a945b4333c        4 days ago          130.3 MB
ubuntu              latest              04c5d3b7b065        2 weeks ago         192.7 MB
centos              centos6             25c5298b1a36        4 weeks ago         215.8 MB
jpetazzo/nsenter    latest              6ed3da1d7fa6        5 weeks ago         367.7 MB
[root@docker-master ~]#

搜索IOS

[root@docker-master ~]# docker search centos
可以查看到镜像的名字 描述 星级 是否官方创建 是否自动创建等等。

下载IOS镜像

[root@docker-master ~]# docker pull centos
Pulling repository centos
acc1b23376ec: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
Status: Downloaded newer image for centos:latest
[root@docker-master ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                  VIRTUAL SIZE
centos              latest              acc1b23376ec        Less than a second ago   224 MB
centos              centos7             acc1b23376ec        Less than a second ago   224 MB
<none>              <none>              3039b31f25fe        4 hours ago              222 MB
ubuntu              12.04               28a945b4333c        4 days ago               130.3 MB
ubuntu              12.04.5             28a945b4333c        4 days ago               130.3 MB
ubuntu              latest              04c5d3b7b065        2 weeks ago              192.7 MB
jpetazzo/nsenter    latest              6ed3da1d7fa6        5 weeks ago              367.7 MB
[root@docker-master ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                  VIRTUAL SIZE
centos              centos7             acc1b23376ec        Less than a second ago   224 MB
centos              latest              acc1b23376ec        Less than a second ago   224 MB
<none>              <none>              3039b31f25fe        4 hours ago              222 MB
ubuntu              12.04               28a945b4333c        4 days ago               130.3 MB
ubuntu              12.04.5             28a945b4333c        4 days ago               130.3 MB
ubuntu              latest              04c5d3b7b065        2 weeks ago              192.7 MB
jpetazzo/nsenter    latest              6ed3da1d7fa6        5 weeks ago              367.7 MB
[root@docker-master ~]#
OpsNotes wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!