命令行安装nginx镜像
安装centos镜像
docker pull centos:6.6
安装nginx
1 | # 创建一个用于运行ngix的容器,并进入交互模式 |
保存容器为镜像
docker commit nginx nginx:1.0
dockerfile安装nginx镜像
编写dockerfile文件
根据上面的命令行操作步骤编写dockerfile文件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
26
27
28
29
30
31
32
33FROM centos:6.6
RUN mkdir /data
RUN yum install wget -y \
&& yum install tar -y \
&& yum install gcc -y \
&& yum install pcre-devel -y \
&& yum install zlib-devel -y
RUN cd /data \
&& wget https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.10.2 \
&& tar -xzvf v0.10.2
RUN cd /data \
&& wget https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.3.0rc1 \
&& tar -xzvf v0.3.0rc1
RUN cd /data \
&& wget http://luajit.org/download/LuaJIT-2.0.0.tar.gz \
&& tar -xzvf LuaJIT-2.0.0.tar.gz \
&& cd ./LuaJIT-2.0.0 \
&& make \
&& make install \
&& cd .. \
&& export LUAJIT_LIB=/usr/local/lib \
&& export LUAJIT_INC=/usr/local/include/luajit-2.0
RUN cd /data \
&& wget http://nginx.org/download/nginx-1.8.1.tar.gz \
&& tar -zxvf nginx-1.8.1.tar.gz \
&& cd nginx-1.8.1 \
&& ./configure --prefix=/usr/local/nginx \
--with-ld-opt="-Wl,-rpath,/usr/local/lib" \
--add-module=/data/ngx_devel_kit-0.3.0rc1 \
--add-module=/data/lua-nginx-module-0.10.2 \
&& make -j2 \
&& make install \
&& cd ..
docker build
1 | cd dockerfile所处目录 |
启动nginx镜像
创建容器并进入命令行
docker run -i -t -p 8080:80 --name nginx_server nginx:1.0 /bin/bash
启动nginx
/usr/local/nginx/sbin/nginx
Detach容器
Ctrl-P + Ctrl-Q
That’s all.
Happy writing!