拉取镜像:(学生云主机非常慢!)
docker pull centos
docker pull nginx
查看已有的镜像:
[root@wang ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 328edcd84f1b 3 weeks ago 192.5 MB
docker.io/nginx latest b8efb18f159b 4 weeks ago 107.5 MB
docker.io/alexwhen/docker-2048 latest 7929bcd70e47 2 years ago 8.011 MB
创建并运行一个容器:centos
[root@wang ~]# docker run -it --name vm1 centos bash
-i: 以交互模式运行容器,通常与 -t 同时使用;
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
--name: 为容器指定一个名称;vm1
bash:在容器内执行/bin/bash命令
查看系统信息:
[root@b26eddb15be0 /]# uname -a
Linux b26eddb15be0 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
* 内核版本号:3.10.0-327.el7.x86_64
* 操作系统版本:1 SMP Thu Nov 19 22:10:57 UTC 2015
* 后面三个x86_64分别代表电脑类型、处理器类型、硬件平台
* GNU/Linux为操作系统名称
[root@b26eddb15be0 /]# cat /proc/version
Linux version 3.10.0-327.el7.x86_64
(builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015
* gcc编译器版本号:gcc version 4.8.3 20140911
* Red Hat版本号:Red Hat 4.8.3-9
[root@b26eddb15be0 /]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
退出之后若还想继续使用:
启动容器:
[root@wang webdata]# docker start vm1
vm1
连接容器:
[root@wang webdata]# docker attach vm1
[root@cc3101f3ecdd /]#
创建并后台运行容器:nginx
[root@wang webdata]# docker run -d --name web -v /tmp/webdata:/usr/share/nginx/html nginx
648e4c03fc3271147b39d33d94ad05145028bbeabc458f096444a605b62b4102
-d:后台运行
-v:主机的目录/tmp/webdata映射到容器的/usr/share/nginx/html
注:主机/tmp/webdata目录下有一个自己创建的index.html文件,并写有内容
查看信息
[root@wang webdata]# docker inspect web
.......
[root@wang webdata]# docker inspect web | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
该容器的IP为:172.17.0.2
测试创建的web容器:
[root@wang webdata]# curl 172.17.0.2
<p>wang</p>
显示的是主机中的/tmp/webdata/index.html中的内容