docker学习笔记之构建镜像

docker 的镜像构建

      手动构建

     手动构建的意义就是在一个最基础的centos镜像上一顿yum安装。其实也不难。下来演示一个构建nginx的镜像。

首先构建基础的centos镜像。并且去下载相关的工具。

# docker run -it -h nginxserver --name nginx-man centos
[root@nginxserver /]# yum -y install wget gcc gcc-g++ make openssl-devel
Loaded plugins: fastestmirror, ovl
base                                                                                                                           | 3.6 kB  00:00:00     

现在源码包。

# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.12.0.tar.gz
# wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz

解压缩

# tar xf nginx-1.12.0.tar.gz 
# tar xf pcre-8.39.tar.gz

添加用户

# useradd -s /sbin/nologin -M www

创建目录

[root@nginxserver nginx-1.12.0]# mkdir -pv /var/tmp/nginx/{client,fcgi,proxy,scgi,uwsgi}
mkdir: created directory '/var/tmp/nginx'
mkdir: created directory '/var/tmp/nginx/client'
mkdir: created directory '/var/tmp/nginx/fcgi'
mkdir: created directory '/var/tmp/nginx/proxy'
mkdir: created directory '/var/tmp/nginx/scgi'
mkdir: created directory '/var/tmp/nginx/uwsgi'

开始编译

[root@nginxserver nginx-1.12.0]# ./configure \ 
> --prefix=/usr \
> --sbin-path=/usr/sbin/nginx \
> --conf-path=/etc/nginx/nginx.conf \
> --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 \
> --user=www \  
> --group=www \
> --with-http_ssl_module \
> --with-http_flv_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --http-client-body-temp-path=/var/tmp/nginx/client \
> --http-proxy-temp-path=/var/tmp/nginx/proxy \
> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
> --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
> --http-scgi-temp-path=/var/tmp/nginx/scgi \
> --with-pcre=/usr/local/src/pcre-8.39 


make && make install

exit 退出。


创建镜像。

# docker commit -m "my nginx" 0ecd209a50a4 454041823/my-nginx:v1
sha256:877ae6c00781abd7170d4154fef03b6d8d4d1d985648e3059a5bbdb1a3e63f95
# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
454041823/my-nginx   v1                  877ae6c00781        16 seconds ago      665MB
python               2.7-slim            1c7128a655f6        7 days ago          183MB
centos               latest              8140d0c64310        7 days ago          193MB
nginx                latest              3448f27c273f        8 days ago          109MB

启动镜像

# docker run -d -p 8000:80 454041823/my-nginx:v1 nginx
# docker ps -l
CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS              PORTS                  NAMES
584f8691dc73        454041823/my-nginx:v1   "nginx"             7 seconds ago       Up 7 seconds        0.0.0.0:8000->80/tcp   loving_curie

OK!可以访问了。



你可能感兴趣的:(运维,云计算)