docker入门(一)

一、什么是docker
docker是一个开源项目,诞生于2013年初,最初是dotCloud公司内部的一个业余项目。它基于Google公司推出的Go语言实现,后来进入Linux基金会,遵从了Apache2.0协议,项目代码在GitHub上进行维护

docker主要目标:

通过对应用组件的封装、分发、部署、运行等生命周期的管理,达到应用级别的一次封装,到处运行的目的(这里的应用组件可以是一个web应用,也可以是一套数据库服务,也可以是一个操作系统的编译器)

二、为什么要使用docker
环境隔离
更快速的交付部署
更高效的资源利用
易迁移扩展
简单的更新管理


三、安装docker(必须64bit的操作系统(因为docker是go语言实现的,go语言需要64bit的环境)

1、sudo yum update #更新 

         2、yum install net-toools #看网络信息

3、配置yum源

        sudo vim /etc/yum.repos.d/docker.repo

[dockerrepo]
name=Docker Repository

baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/

enabled=1

gpgcheck=1

gpgkey=https://yum.dockerproject.org/gpg
   4、sudo yum install docker

   5、service docker start #启动docker

    6、docker version #查看docker版本

    7、测试docker是否安装成功

    

[zzq@localhost ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

这样的结果就算成功了。

    8、docker一些实用命令:

             docker查看正在运行的容器:

[root@VM_0_6_centos software]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
45459695f7db        ff426288ea90        "/bin/bash"         5 weeks ago         Up 5 weeks                              elated_keller

             docker查看容器IP命令:

docker inspect 容器ID | grep IPAddress
[root@VM_0_6_centos software]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
45459695f7db        ff426288ea90        "/bin/bash"         5 weeks ago         Up 5 weeks                              elated_keller
[root@VM_0_6_centos software]# docker inspect 45459695f7db | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",


posted on 2017-04-04 19:56  愤怒的苹果ext  阅读(24)  评论(0编辑  收藏  举报

导航