1、查看本地的Docker Images
tu:~/myWeb# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 8251da35e7a7 2 weeks ago 188.4 MB
2、创建并运行一个Docker容器
root@ubuntu:~/myWeb# docker run -i -t ubuntu:14.04 /bin/bash
root@be8438d3ddd3:/#
3、安装nginx
root@be8438d3ddd3:/# apt-get install -y nginx
Reading package lists... Done
……………………
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...
root@be8438d3ddd3:/#
4、修改nginx的默认index.html文件并退出容器
root@be8438d3ddd3:/# cd /usr/share/nginx/html/
50x.html index.html
root@be8438d3ddd3:/# exit
root@ubuntu:~/myWeb#
5、找到我们刚才运行的容器
root@ubuntu:~/myWeb# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be8438d3ddd3 ubuntu:14.04 /bin/bash 17 minutes ago Exited (127) 18 seconds ago desperate_davinci
0dd36b9ec4e8 5d6887a4f8c4 /bin/sh -c 'apt-get 43 minutes ago Exited (100) 28 minutes ago sick_meitner
6、创建镜像
root@ubuntu:~/myWeb# docker commit be8438d3ddd3 lingyu/nginx1.0
4acd6e89f55c6e959ac783a2287e53dd81bdce41e42949317ef3fc283b63b796
root@ubuntu:~/myWeb#
7、这是就可以查看我们刚才创建的镜像了
root@ubuntu:~/myWeb# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
lingyu/nginx1.0 latest 4acd6e89f55c 8 seconds ago 206.5 MB
ubuntu 14.04 8251da35e7a7 2 weeks ago 188.4 MB
root@ubuntu:~/myWeb#
8、使用镜像运行并指定映射的端口号
root@ubuntu:/# docker run -d --name myNginx -p 9000:80 lingyu/nginx1.0 nginx -g "daemon off;"
63babea0809338f93d035ae69378e10ed5dcaf49a748ffd461d87dcaaa8d455e
9、使用docker ps查看当前正在运行的容器
root@ubuntu:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63babea08093 lingyu/nginx1.0:latest nginx -g 'daemon off 15 minutes ago Up 15 minutes 0.0.0.0:9000->80/tcp myNginx
10、使用浏览器访问即可
宿主机IP地址为192.168.170.134,所以在浏览器中输入http://192.168.170.134:9000 即可访问我们刚才修改的index.html文件