基于docker的centos:latest镜像制作nginx的镜像

Dockerfile和nginx.repo在同一目录下

先创建nginx.repo

[root@localhost nginx]# cat nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
[root@localhost nginx]# ls
Dockerfile  nginx.repo

  

写dockerfile

[root@localhost nginx]# cat Dockerfile 
# This is My first Dockerfile
# Version 1.0
# Author: Liuzhengwei
# Base images
FROM centos:base_newlatest
MAINTAINER mail:1135960569@qq.com
ADD nginx.repo /etc/yum.repos.d
RUN yum install nginx -y
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN useradd -s /sbin/nologin -M www
EXPOSE 80
CMD ["nginx"]

   

创建镜像:

[root@localhost nginx]# docker build -t nginx-file:v1 .
......
Removing intermediate container 57b75e5a35e7
Step 8/8 : CMD nginx
 ---> Running in 062fddcc03ed
 ---> f4a750280b72
Removing intermediate container 062fddcc03ed
Successfully built f4a750280b72

  

运行此镜像:

[root@localhost nginx]# docker run -d -p 80 nginx-file:v1
6e43d596879c2b67fc74143957ef914ef842d78046812717919e576a629f694c

   

查看容器是否启动正常:

[root@localhost nginx]# docker ps
CONTAINER ID      IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
6e43d596879c        nginx-file:v1       "nginx"                  7 minutes ago       Up 7 minutes        0.0.0.0:32774->80/tcp            sleepy_shannon

   

进入此容器:

[root@localhost nginx]# docker exec -it 6e43d596879c bash
[root@6e43d596879c /]# ps -ef | grep nginx
root         1     0  0 15:58 ?        00:00:00 nginx: master process nginx
nginx        7     1  0 15:58 ?        00:00:00 nginx: worker process

  

实际示例:

[root@master01 nginx]# ls
Dockerfile  fashion_bi_dev.conf  nginx.repo  web-fashion-bi 

  

[root@master01 nginx]# cat Dockerfile 
# This is My first Dockerfile
# Version 1.0
# Author: Liuzhengwei
# Base images
FROM centos
MAINTAINER mail:1135960569@qq.com

WORKDIR /
 
RUN mkdir data

ADD nginx.repo /etc/yum.repos.d
RUN yum install nginx -y
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

RUN rm -rf /etc/nginx/conf.d/default.conf

ADD fashion_bi_dev.conf /etc/nginx/conf.d/

COPY web-fashion-bi /data/web-fashion-bi

RUN useradd -s /sbin/nologin -M www
EXPOSE 80
CMD ["nginx"]

  

docker build -t nginx-file:v6 .

docker run -d -p 80 nginx-file:v6

  

[root@master01 nginx]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
46fc3f005313        nginx-file:v6       "nginx"             2 minutes ago       Up 2 minutes        0.0.0.0:32773->80/tcp   distracted_lovelace

  

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值