Ubuntu中Docker通过Dockerfile构建常用的基础环境
root@ubuntu:~# mkdir /dockerfile/cct -p
root@ubuntu:~# cd /dockerfile/cct/
root@ubuntu:/dockerfile/cct# vim sources.list
root@ubuntu:/dockerfile/cct# cat sources.list
deb http://mirrors.aliyun.com/ubuntu/ trusty mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trustymain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse
root@ubuntu:/dockerfile/cct#
root@ubuntu:/dockerfile/cct#vim Dockerfile
root@ubuntu:/dockerfile/cct#cat Dockerfile
# 设置基本的镜像,后续命令都以这个镜像为基础
FROM ubuntu
# 作者信息
MAINTAINER shangwu
# RUN命令会在上面指定的镜像里执行任何命令
RUN cp/etc/apt/sources.list /etc/apt/sources.list.bak
COPYsources.list /etc/apt/
RUN apt-get update
RUN apt-get install -y iputils-ping
RUN apt-get install -y nginx
RUN apt-get install -y curl
RUN apt-get install -y vim
RUN apt-get install -y net-tools
RUN apt-get install -y lrzsz
#暴露ssh端口
EXPOSE 80
CMD/bin/bash
root@ubuntu:/dockerfile/cct#
root@ubuntu:/dockerfile/cct#docker build -t cct .
root@ubuntu:/dockerfile/cct#
root@ubuntu:/dockerfile/cct#docker run -it --name cct2 cct
root@cc2c3391df90:/# ifconfig
eth0 Link encap:Ethernet HWaddr02:42:c0:a8:64:1a
inet addr:192.168.100.26 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::42:c0ff:fea8:641a/64 Scope:Link
UPBROADCAST RUNNING MTU:1500 Metric:1
RXpackets:6 errors:0 dropped:0 overruns:0 frame:0
TXpackets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:508 (508.0 B) TX bytes:418 (418.0B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:65536 Metric:1
RXpackets:0 errors:0 dropped:0 overruns:0 frame:0
TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:0 (0.0 B) TX bytes:0 (0.0 B)
root@cc2c3391df90:/#
root@cc2c3391df90:/#rz -y
root@cc2c3391df90:/# **B0100000023be50
root@cc2c3391df90:/#vim test
root@cc2c3391df90:/#
root@cc2c3391df90:/#ping www.baidu.com
root@cc2c3391df90:/#cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ trusty mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trustymain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse
root@cc2c3391df90:/#
root@cc2c3391df90:/#nginx
root@cc2c3391df90:/# ps -ef|grep nginx
root 19 1 0 11:30 ? 00:00:00 nginx: master process nginx
www-data 20 19 0 11:30 ? 00:00:00 nginx: worker process
www-data 21 19 0 11:30 ? 00:00:00 nginx: worker process
www-data 22 19 0 11:30 ? 00:00:00 nginx: worker process
www-data 23 19 0 11:30 ? 00:00:00 nginx: worker process
root 25 7 0 11:30 ? 00:00:00 grep --color=auto nginx
root@cc2c3391df90:/#
root@cc2c3391df90:/#curl -I www.baidu.com
HTTP/1.1 200 OK
Server: bfe/1.0.8.18
Date: Sun, 02 Jul 2017 11:30:57 GMT
Content-Type: text/html
Content-Length: 277
Last-Modified: Mon, 13 Jun 2016 02:50:26 GMT
Connection: Keep-Alive
ETag: "575e1f72-115"
Cache-Control: private, no-cache, no-store,proxy-revalidate, no-transform
Pragma: no-cache
Accept-Ranges: bytes
root@cc2c3391df90:/#