1、基于基础镜像centos:7
[root@localhost ~]# vim Dockerfile
FROM centos:7
2、维护者信息
MAINTAINER renweiwei@example.com
3、添加Centos-7仓库
ADD Centos-7.repo /etc/yum.repos.d/
4、添加epel-7仓库
ADD epel-7.repo /etc/yum.repos.d/
5、安装nginx软件包
RUN yum -y install nginx
6、暴露指定端口80
EXPOSE 80
CMD ["/usr/sbin/nginx","-g","daemon off;"]
7、构建镜像,镜像名称为nginx:v1
[root@localhost ~]# docker build -t nginx:v1 .
Sending build context to Docker daemon 73.88MB
Step 1/7 : FROM centos:7
---> eeb6ee3f44bd
Step 2/7 : MAINTAINER renweiwei@example.com
---> Running in 014482fe92f4
Removing intermediate container 014482fe92f4
---> 5cead95e0897
Step 3/7 : ADD Centos-7.repo /etc/yum.repos.d/
---> 5f930fea9725
Step 4/7 : ADD epel-7.repo /etc/yum.repos.d/
---> eee72966ed25
Step 5/7 : RUN yum -y install nginx
---> Running in 2ff6dc088303
Loaded plugins: fastestmirror, ovl
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx v1 9834d41efa5f 7 minutes ago 459MB
centoscy latest e2f07109ba1f 4 hours ago 402MB
nginx latest 2b7d6430f78d 7 days ago 142MB
8、运行容器,容器名称为自己名字的全拼,映射端口88:80
[root@localhost ~]# docker run -d --name renweiwei -p 88:80 nginx:v1
e00d5b3e320b6daa18519fc8eba36cbc2ba3450ece2d60ec31269d07111e09ba
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e00d5b3e320b nginx:v1 "/usr/sbin/nginx -g …" 22 seconds ago Up 21 seconds 0.0.0.0