本文介绍了docker 手动构建新镜像的方法,分享给大家,具体如下:
查看本地现有镜像:
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c59f17fe53b0 4 days ago 108MB
ubuntu latest 747cb2d60bbe 3 weeks ago 122MB
centos latest 196e0ce0c9fb 6 weeks ago 197MB现在利用基础镜像centos,在此基础上手动构建一个web服务,这里采用nginx
启动一个container并进入到容器内:
[root@docker ~]# docker run -it --name=web centos /bin/bash
[root@bab3b6991467 /]#然后在容器内进行安装nginx服务:
[root@bab3b6991467 /]# cd /usr/local/src/
[root@bab3b6991467 src]# yum install wget vim这里采用编译安装nginx,所以下载nginx源码包,并安装好编译环境:
[root@bab3b6991467 src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz编译环境:
[root@bab3b6991467 src]# yum install gcc gcc-c++ glibc make autoconf openssl openssl-devel安装nginx的一些依赖包:
[root@bab3b6991467 src]# yum install libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel然后开支执行安装:
[root@bab3b6991467 src]# ll
total 960
-rw-r--r--. 1 root root 981687 Oct 17 13:20 nginx-1.12.2.tar.gz
[root@bab3b6991467 src]# tar xf nginx-1.12.2.tar.gz
[root@bab3b6991467 src]# cd nginx-1.12.2
[root@bab3b6991467 nginx-1.12.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module创建需要用到的用户:
useradd -M -s /sbin/nologin nginx继续编译:
make && make install
chown -R nginx:nginx /usr/local/nginx/这里需要介绍nginx命令的一个参数:
[root@bab3b6991467 ~]# /usr/local/nginx/sbin/nginx -h
-g directives : set global directives out of configuration file-g:为nginx的配置文件设置指令
现在退出container,回到host本机










