基于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

  

原文地址:https://www.cnblogs.com/weifeng1463/p/10060187.html