1,下载镜像
首先,我们需要一个系统,以官方的centos为例,先pull下来
[root@zabbix-3 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a3ed95caeb02: Already exists
a3ed95caeb02: Already exists
Digest: sha256:1a62cd7c773dd5c6cf08e2e28596f6fcc99bd97e38c9b324163e0da90ed27562
Status: Image is up to date for centos:latest
[root@zabbix-3 ~]#
2,在启动容器,进行编译安装
[root@zabbix-3 ~]# docker run --name nginx-create -it centos
[root@e0d020800f10 /]#
在容器中安装常用包和依赖包
[root@e0d020800f10 /]# yum install wget gcc gcc-c++ make openssl-devel -y
[root@e0d020800f10 /]# wget -P /usr/local/src/ http://nginx.org/download/nginx-1.10.1.tar.gz
[root@e0d020800f10 /]# wget -P /usr/local/src/ http://tenet.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz
[root@e0d020800f10 src]# cd /usr/local/src/
[root@e0d020800f10 src]# tar xf nginx-1.10.1.tar.gz
[root@e0d020800f10 src]# tar xf pcre-8.39.tar.gz
[root@e0d020800f10 src]# useradd -s /sbin/nologin -M nginx
[root@e0d020800f10 src]# cd nginx-1.10.1
[root@e0d020800f10 nginx-1.10.1]# ./configure
--prefix=/usr/local/nginx
--conf-path=/etc/nginx/nginx.conf
--user=nginx
--group=nginx
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--with-http_ssl_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-http_flv_module
--with-http_mp4_module
--with-pcre=/usr/local/src/pcre-8.39
[root@e0d020800f10 nginx-1.10.1]# make && make install
[root@e0d020800f10 nginx-1.10.1]# sed -i '2 idaemon off;' /etc/nginx/nginx.conf
3, commit提交
而后退出,commit提交,多次commit提交名称不能一致
[root@zabbix-3 ~]# docker commit -m "v3" a1359ffc377f mark/nginx:v3
sha256:18b54107232173c19e827005ccf2582b10ff316c224e6c6899ecc9ed19afc0c0
4,提交完成查看
[root@zabbix-3 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mark/nginx v3 57289bc1d1f0 3 minutes ago 401.6 MB
mark/nginx v2 b20b274f88ee 4 minutes ago 401.6 MB
mark/nginx v1 18b541072321 About an hour ago 401.6 MB
registry.ds.com/zabbix-3.0-xxl latest 59ac231a6d23 7 days ago 745.4 MB
centos latest 904d6c400333 3 weeks ago 196.7 MB
registry.ds.com/centos latest 904d6c400333 3 weeks ago 196.7 MB
nginx latest 0d409d33b27e 3 weeks ago 182.7 MB
registry.ds.com/nginx latest 0d409d33b27e 3 weeks ago 182.7 MB
[root@zabbix-3 ~]#
5,启动
当提交完成且出现在images中后,才可以映射端口来启动
[root@zabbix-3 ~]# docker run -d -p 100:80 mark/nginx:v3 /usr/local/nginx/sbin/nginx
59e7cc86f4815245ff8b97962d600a2008910b36795a374704ce547bfd79671d
[root@zabbix-3 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
da346dfe0477 mark/nginx:v3 "/usr/local/nginx/sbi" 4 minutes ago Up 4 minutes 0.0.0.0:100->80/tcp big_khorana
[root@zabbix-3 ~]#