基于docker的centos:latest镜像制作nginx的镜像
Dockerfile和nginx.repo在同一目录下先创建nginx.repo
1
2
3
4
5
6
7
8
# cat nginx.repo
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
# ls
Dockerfilenginx.repo
写dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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"]
创建镜像:
1
2
3
4
5
6
7
8
# 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
运行此镜像:
1
2
# docker run -d -p 80 nginx-file:v1
6e43d596879c2b67fc74143957ef914ef842d78046812717919e576a629f694c
查看容器是否启动正常:
1
2
3
# 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
进入此容器:
1
2
3
4
5
# docker exec -it 6e43d596879c bash
# ps -ef | grep nginx
root 1 00 15:58 ? 00:00:00 nginx: master process nginx
nginx 7 10 15:58 ? 00:00:00 nginx: worker process
# ss -tnl
页:
[1]