Docker学习笔记二:安装Docker并管理镜像

来源:互联网 发布:mac下最好的输入法 编辑:程序博客网 时间:2024/06/05 16:14

安装并运行hello-world

安装Docker(以CentOS 7.x为例)

安装前须知:Docker需要64位操作系统和3.10或更高版本的Linux内核。 
使用如下命令检查当前内核版本:

$ uname -r3.10.0-229.el7.x86_64
  • 1
  • 2
  • 1
  • 2

推荐将系统更新到最新。

1、确保系统更新到了最新:

$ sudo yum update -y
  • 1
  • 1

2、添加yum仓库:

$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'[dockerrepo]name=Docker Repositorybaseurl=https://yum.dockerproject.org/repo/main/centos/7/enabled=1gpgcheck=1gpgkey=https://yum.dockerproject.org/gpgEOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3、安装Docker包:

$ sudo yum install docker-engine
  • 1
  • 1

4、启用服务:

$ sudo systemctl enable docker.service
  • 1
  • 1

5、启动Docker守护进程:

$ sudo systemctl start docker
  • 1
  • 1

验证安装

1.在命令行执行docker version

$ docker versionClient: Version:      1.12.3 API version:  1.24 Go version:   go1.6.3 Git commit:   6b644ec Built: OS/Arch:      linux/amd64Server: Version:      1.12.3 API version:  1.24 Go version:   go1.6.3 Git commit:   6b644ec Built: OS/Arch:      linux/amd64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

2.输入docker run ubuntu /bin/echo 'hello-world' 命令并回车:

$ docker run ubuntu /bin/echo 'hello world'Unable to find image 'ubuntu:latest' locallylatest: Pulling from library/ubuntucad964aed91d: Pull complete3a80a22fea63: Pull complete50de990d7957: Pull complete61e032b8f2cb: Pull complete9f03ce1741bf: Pull completeDigest: sha256:28d4c5234db8d5a634d5e621c363d900f8f241240ee0a6a978784c978fe9c737Status: Downloaded newer image for ubuntu:latesthello world
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

查看到这些信息,则证明安装完成。 
若刚安装完Docker或者本地没有ubuntu镜像,docker会从Docker hub下载ubuntu image并运行一个容器,执行完/bin/echo 'hello world' 命令执行完成后容器退出。

镜像管理

列出主机上已有的镜像

$ docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEubuntu              latest              c73a085dc378        28 hours ago        127.1 MBcomposetest_web     latest              b241384399ea        5 days ago          682.4 MBweb                 latest              11dd84ade57e        5 days ago          682.4 MB<none>              <none>              60803d8976d7        5 days ago          675.3 MBpython              2.7                 4c5f5839b372        3 weeks ago         675.3 MBredis               latest              0d1cbfaa41da        4 weeks ago         185 MBmysql               5.7.14              4b3b6b994512        5 weeks ago         384.5 MBhello-world         latest              c54a2cc56cbb        12 weeks ago        1.848 kBmedicean/vulapps    latest              689d86032c20        3 months ago        360.1 MBnginx               latest              0d409d33b27e        3 months ago        182.8 MBtraining/webapp     latest              6fae60ef3446        16 months ago       348.8 MB
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

搜索在线Docker image

$ docker search ubuntuNAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATEDubuntu                            Ubuntu is a Debian-based Linux operating s...   4771      [OK]ubuntu-upstart                    Upstart is an event-based replacement for ...   66        [OK]rastasheep/ubuntu-sshd            Dockerized SSH service, built on top of of...   42                   [OK]ubuntu-debootstrap                debootstrap --variant=minbase --components...   27        [OK]torusware/speedus-ubuntu          Always updated official Ubuntu docker imag...   27                   [OK]nickistre/ubuntu-lamp             LAMP server on Ubuntu                           9                    [OK]nuagebec/ubuntu                   Simple always updated Ubuntu docker images...   8                    [OK]nickistre/ubuntu-lamp-wordpress   LAMP on Ubuntu with wp-cli installed            6                    [OK]nimmis/ubuntu                     This is a docker images different LTS vers...   5                    [OK]maxexcloo/ubuntu                  Base image built on Ubuntu with init, Supe...   2                    [OK]darksheer/ubuntu                  Base Ubuntu Image -- Updated hourly             1                    [OK]admiringworm/ubuntu               Base ubuntu images based on the official u...   1                    [OK]jordi/ubuntu                      Ubuntu Base Image                               1                    [OK]lynxtp/ubuntu                     https://github.com/lynxtp/docker-ubuntu         0                    [OK]life360/ubuntu                    Ubuntu is a Debian-based Linux operating s...   0                    [OK]widerplan/ubuntu                  Our basic Ubuntu images.                        0                    [OK]esycat/ubuntu                     Ubuntu LTS                                      0                    [OK]datenbetrieb/ubuntu               custom flavor of the official ubuntu base ...   0                    [OK]webhippie/ubuntu                  Docker images for ubuntu                        0                    [OK]teamrock/ubuntu                   TeamRock's Ubuntu image configured with AW...   0                    [OK]dorapro/ubuntu                    ubuntu image                                    0                    [OK]uvatbc/ubuntu                     Ubuntu images with unprivileged user            0                    [OK]konstruktoid/ubuntu               Ubuntu base image                               0                    [OK]ustclug/ubuntu                    ubuntu image for docker with USTC mirror        0                    [OK]gopex/ubuntu                      Automatic build of GoPex customization ove...   0                    [OK]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

下载image

$ docker pull ubuntu
  • 1
  • 1

下载指定版本的image

$ docker pull ubuntu:14:04
0 0