手动构建Docker镜像
1、运行一个容器,并且在容器中安装和配置nginx
|
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
|
[root@docker /]
# docker run --name nginx-man -it centos
[root@37d5b354b661 /]
# yum install -y wget gcc gcc-c++ make openssl-devel
[root@37d5b354b661 /]
# wget http://nginx.org/download/nginx-1.9.11.tar.gz
--2016-02-24 06:14:44-- http:
//nginx
.org
/download/nginx-1
.9.11.
tar
.gz
Resolving nginx.org (nginx.org)... 95.211.80.227, 206.251.255.63, 2001:1af8:4060:a004:21::e3, ...
Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 895373 (874K) [application
/octet-stream
]
Saving to:
'nginx-1.9.11.tar.gz'
100%[==========================================================================================================>] 895,373 357KB
/s
in
2.5s
2016-02-24 06:14:46 (357 KB
/s
) -
'nginx-1.9.11.tar.gz'
saved [895373
/895373
]
[root@37d5b354b661 /]
# cd /usr/local/src
[root@37d5b354b661 src]
# tar zxvf pcre-8.38.tar.gz
[root@37d5b354b661 src]
# tar zxvf nginx-1.9.11.tar.gz
[root@37d5b354b661 src]
# useradd -s /sbin/nologin -M www
[root@37d5b354b661 src]
# pwd
/usr/local/src
[root@37d5b354b661 src]
# ls
nginx-1.9.11 nginx-1.9.11.
tar
.gz pcre-8.38 pcre-8.38.
tar
.gz
[root@37d5b354b661 src]
# cd nginx-1.9.11
[root@37d5b354b661 nginx-1.9.11]
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.38
[root@37d5b354b661 nginx-1.9.11]
# make
[root@37d5b354b661 nginx-1.9.11]
# make install
[root@37d5b354b661 nginx-1.9.11]
# echo $?
[root@37d5b354b661 nginx-1.9.11]
# vi /usr/local/nginx/conf/nginx.conf
|
添加信息:
daemon off;
允许后台允许nginx:
|
1
2
3
4
|
[root@37d5b354b661 nginx-1.9.11]
# echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
设置开机自动启动(经过测试发现不能自动生效):
[root@37d5b354b661 nginx-1.9.11]
# vi /etc/rc.local
[root@37d5b354b661 nginx-1.9.11]
# echo "/usr/local/nginx/sbin/nginx">>/etc/rc.local
|
2、将配置好的容器,当作一个镜像进行手动提交(wanlong/my-nginx:v3):
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@docker ~]
# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
494d0139baf9 wanlong
/my-nginx
:v2
"/bin/bash"
6 minutes ago Up 6 minutes lonely_curie
[root@docker ~]
# docker commit -m "my nginx" 494d0139baf9 wanlong/my-nginx:v3
76507d1d9b41a5189eddd641f2ecbc1b19516eb83d8215dddc73887ca49f4bef
[root@docker ~]
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
wanlong
/my-nginx
v3 76507d1d9b41 5 seconds ago 517.2 MB
wanlong
/my-nginx
v2 b36ee38d811b 13 minutes ago 517.2 MB
ubuntu latest c29e52d44f69 6 days ago 187.9 MB
wordpress latest 62a9acf5fc2a 12 days ago 517.3 MB
nginx latest bbb75b846e7b 12 days ago 134.5 MB
dockerui
/dockerui
latest 95c8b9dc91e0 3 weeks ago 6.13 MB
redis latest 34ca6ac180ad 3 weeks ago 151.2 MB
mongo latest ad74160b3443 3 weeks ago 317.4 MB
daocloud.io
/library/python
latest a2db1214d015 4 weeks ago 689.1 MB
debian latest 5eb1402f0414 4 weeks ago 125.1 MB
centos latest 60e65a8e4030 8 weeks ago 196.6 MB
joedval
/stress
latest 7eb627cb08a2 11 weeks ago 214.9 MB
jpetazzo
/nsenter
latest 10cbe4e038bc 5 months ago 368.3 MB
lemonbar
/centos6-ssh
latest b78c71c001db 19 months ago 296.9 MB
|
3、使用提交过的镜像,运行新的容器
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@docker ~]
# docker run -d -p 9999:80 wanlong/my-nginx:v3 /usr/local/nginx/sbin/nginx
656058dc0375d3a88ebb8407e64f10542c95e5185b9335c0e50ae1de0be0cee2
[root@docker ~]
# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
656058dc0375 wanlong
/my-nginx
:v3 "
/usr/local/nginx/sb
8 seconds ago Up 6 seconds 0.0.0.0:9999->80
/tcp
backstabbing_thompson
[root@docker ~]
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
656058dc0375 wanlong
/my-nginx
:v3 "
/usr/local/nginx/sb
8 minutes ago Up 8 minutes 0.0.0.0:9999->80
/tcp
backstabbing_thompson
494d0139baf9 wanlong
/my-nginx
:v2
"/bin/bash"
17 minutes ago Up 17 minutes lonely_curie
37d5b354b661 centos
"/bin/bash"
2 hours ago Up 2 hours nginx-
man
94ea720a2c41 centos
"/bin/bash"
4 hours ago Up 4 hours volume-test04
8884fc392971 nginx "nginx -g 'daemon of 18 hours ago Up 6 hours 80
/tcp
, 443
/tcp
nginxdocker
14caa9ab03a9 dockerui
/dockerui
"/dockerui"
2 days ago Up 6 hours 0.0.0.0:9000->9000
/tcp
dockerui_qinwen
e278cabec91e centos
"/bin/bash"
2 days ago Up 6 hours centos_aways
|
在浏览器中输入:http://192.168.1.129:9999/,可以看到nginx的默认界面,配置成功