1. 程式人生 > >基於docker的centos:latest映象製作nginx的映象

基於docker的centos:latest映象製作nginx的映象

Dockerfile和nginx.repo在同一目錄下

先建立nginx.repo

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

  

寫dockerfile

[[email protected]
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"]

   

建立映象:

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

  

執行此映象:

[[email protected] nginx]# docker run -d -p 80 nginx-file:v1
6e43d596879c2b67fc74143957ef914ef842d78046812717919e576a629f694c

   

檢視容器是否啟動正常:

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

   

進入此容器:

[[email protected] nginx]# docker exec -it 6e43d596879c bash
[[email protected] /]# 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