免费分享
技术和面试资料

基于centos7制作docker镜像

基于centos7制作docker镜像

docker镜像是企业非常常用的一种应用打包,应用交付的方式. docker天生优势,一处构建处处运行,在任何机器构建的服务均可以在任意一台安装有docker的主机上运行

1. docker构建nginx镜像

1. 首先安装centos7平台环境
docker run -itd --name centos7 cenots:7

2. 进入cenots7
docker  exec -it centos7 bash

3. 安装yum源

curl  -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release
yum clean all

3. 安装nginx依赖包
yum install -y pcre pcre-devel openssl openssl-devel 
    gd-devel  zlib-devel gcc net-tools iproute telnet wget curl && 
rm -rf /var/cache/yum/*

4. 安装nginx
wget https://www.chenleilei.net/soft/nginx-1.16.1.tar.gz
tar xf nginx-1.16.1.tar.gz && 
cd  nginx-1.16.1 && 
    ./configure --prefix=/usr/local/nginx --with-http_image_filter_module 
    --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module  && 
make -j 4 && make install && 
rm -rf /usr/local/nginx/html/*  && 
echo "leilei hello" >/usr/local/nginx/html/index.html  && 
cd / && rm -rf nginx* && 
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

--------------------------------------------------
5. 书写nginx  docker file
vim dockerfile 
---------------------------------------------------------------
FROM centos:7
LABEL maintainer www.chenleilei.net
RUN yum install -y cmake pcre pcre-devel openssl openssl-devel gd-devel 
    zlib-devel gcc gcc-c++ net-tools iproute telnet wget curl &&
    yum clean all && 
    rm -rf /var/cache/yum/*
RUN wget https://www.chenleilei.net/soft/nginx-1.16.1.tar.gz
RUN tar xf nginx-1.16.1.tar.gz
WORKDIR nginx-1.16.1
RUN ./configure --prefix=/usr/local/nginx --with-http_image_filter_module 
    --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module  && 
    make -j 4 && make install && 
    rm -rf /usr/local/nginx/html/*  && 
    echo "leilei hello" >/usr/local/nginx/html/index.html  && 
    rm -rf nginx* && 
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/nginx/sbin
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
EXPOSE 80
WORKDIR /usr/local/nginx
CMD ["nginx","-g","daemon off;"]
---------------------------------------------------------------
##注意点: COPY nginx.conf /usr/local/nginx/conf/nginx.conf 这一句的nginx必须在当前执行的目录中,他是将nginx.conf文件拷贝到容器中替代容器的nginx.conf文件.

6. docker 构建:
   docker build -t nginx:v1 -f dockerfile .

7. 使用这个镜像
   docker run --name a-nginx -d -p 80:80 --restart=always nginx:v1

7. docker运行测试:
docker start nginx

[root@master1 ~]# docker ps -a
CONTAINER ID  IMAGE    OMMAND                  CREATED       STATUS   PORTS                NAMES
2b79fdc30a2d  nginx:v2 "nginx -g 'daemon of…"  5 seconds ago Up 4     0.0.0.0:80->80/tcp   a-nginx


8.  访问测试:

未经允许不得转载:软件实施库 » 基于centos7制作docker镜像

分享到: 更多 (0)
avatar

开发实施交流群

加入组织
切换注册

登录

忘记密码 ?

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活