系统环境

linux版本:centos7

[root@zk1 ~]# uname -r
3.10.0-327.el7.x86_64
[root@zk1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

安装步骤

  • 更新yumyum update
  • 安装dockeryum install docker
  • 安装成功后查看docker版本docker version

    [root@zk1 docker]# docker version 
    Client:
    Version:         1.10.3
    API version:     1.22
    Package version: docker-common-1.10.3-46.el7.centos.14.x86_64
    Go version:      go1.6.3
    Git commit:      cb079f6-unsupported
    Built:           Fri Sep 16 13:24:25 2016
    OS/Arch:         linux/amd64
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    You have new mail in /var/spool/mail/root
    
  • 启动docker服务[root@zk1 docker]# /bin/systemctl start docker.service

  • 再次查看docker版本:
 [root@zk1 docker]# docker version 
Client:
 Version:         1.10.3
 API version:     1.22
 Package version: docker-common-1.10.3-46.el7.centos.14.x86_64
 Go version:      go1.6.3
 Git commit:      cb079f6-unsupported
 Built:           Fri Sep 16 13:24:25 2016
 OS/Arch:         linux/amd64

Server:
 Version:         1.10.3
 API version:     1.22
 Package version: docker-common-1.10.3-46.el7.centos.14.x86_64
 Go version:      go1.6.3
 Git commit:      cb079f6-unsupported
 Built:           Fri Sep 16 13:24:25 2016
 OS/Arch:         linux/amd64

docker初体验

  • 下载安装镜像tutorial
docker search tutorial
docker pull learn/tutorial
  • 运行自带的helloword程序
 [root@zk2 software]# docker run learn/tutorial echo “hello word”
“hello word”
  • 在容器中安装新的程序(wget命令)
[root@zk2 software]# docker run learn/tutorial apt-get install -y wget
  • 使用docker ps -l命令获得安装完ping命令之后容器的id。然后把这个镜像保存为learn/wget。
[root@zk2 software]# docker ps -l 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
421401d23ba8        learn/tutorial      "apt-get install -y w"   2 minutes ago       Exited (0) 2 minutes ago                       suspicious_lamarr
  • 保存对容器的修改 421401d23ba8为上面container编号
[root@zk2 software]# docker commit 421401d23ba8 learn/wget 
sha256:1a444d64177690c5384db52e10bf5b99722bc486adff7a2723ff8b05d3255136
  • 检查运行中的镜像 docker inspect 421401d23ba8
  • 发布自己的镜像
    a. 首先在https://cloud.docker.com 注册,并且创建一个Repositories
    b. 将刚才我们做的镜像起个新的名字[root@zk2 software]# docker tag learn/wget:latest 852026881/learn:latest
    c. 在命令行登录[root@zk2 software]# docker login
    d. 上传 [root@zk2 software]# docker push 852026881/learn:latest

至此,整个docker的使用已体验完啦!

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐