基于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:[email protected]
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

  

猜你喜欢

转载自www.cnblogs.com/weifeng1463/p/10060187.html