安装并运行hello-world
安装Docker(以CentOS 7.x为例)
安装前须知:Docker需要64位操作系统和3.10或更高版本的Linux内核。
使用如下命令检查当前内核版本:
$ uname -r
3.10.0-229.el7.x86_64
推荐将系统更新到最新。
1、确保系统更新到了最新:
$ sudo yum update -y
2、添加yum仓库:
$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
3、安装Docker包:
$ sudo yum install docker-engine
4、启用服务:
$ sudo systemctl enable docker.service
5、启动Docker守护进程:
$ sudo systemctl start docker
验证安装
1.在命令行执行docker version
:
$ docker version
Client:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built:
OS/Arch: linux/amd64
Server:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built:
OS/Arch: linux/amd64
2.输入docker run ubuntu /bin/echo 'hello-world'
命令并回车:
$ docker run ubuntu /bin/echo 'hello world'
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
cad964aed91d: Pull complete
3a80a22fea63: Pull complete
50de990d7957: Pull complete
61e032b8f2cb: Pull complete
9f03ce1741bf: Pull complete
Digest: sha256:28d4c5234db8d5a634d5e621c363d900f8f241240ee0a6a978784c978fe9c737
Status: Downloaded newer image for ubuntu:latest
hello world
查看到这些信息,则证明安装完成。
若刚安装完Docker或者本地没有ubuntu镜像,docker会从Docker hub下载ubuntu image并运行一个容器,执行完/bin/echo 'hello world'
命令执行完成后容器退出。
镜像管理
列出主机上已有的镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest c73a085dc378 28 hours ago 127.1 MB
composetest_web latest b241384399ea 5 days ago 682.4 MB
web latest 11dd84ade57e 5 days ago 682.4 MB
<none> <none> 60803d8976d7 5 days ago 675.3 MB
python 2.7 4c5f5839b372 3 weeks ago 675.3 MB
redis latest 0d1cbfaa41da 4 weeks ago 185 MB
mysql 5.7.14 4b3b6b994512 5 weeks ago 384.5 MB
hello-world latest c54a2cc56cbb 12 weeks ago 1.848 kB
medicean/vulapps latest 689d86032c20 3 months ago 360.1 MB
nginx latest 0d409d33b27e 3 months ago 182.8 MB
training/webapp latest 6fae60ef3446 16 months ago 348.8 MB
搜索在线Docker image
$ docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu 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]
下载image
$ docker pull ubuntu
下载指定版本的image
$ docker pull ubuntu:14:04