一
- [ ~]#docker run --name mynginx01 -it centos
- [ ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 84bcc294325b nginx "nginx -g 'daemon off" 3 seconds ago Up 3 seconds
2. 此时已经进入容器
- yum -y install wget
- wget -O /etc/yum.repos.d/epel.repo
- yum -y install nginx
- vim /etc/nginx /nginx.conf
- ...
- daemon off;
- 退出
3, 制作镜像
二. Dokcerfile 制作镜像
- [ dockerfile]# cat Dockerfile
- FROM centos
- MAINTAINER liuhaixiao
- RUN yum -y install wget
- RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
- RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- RUN yum clean all && yum install nginx -y
- RUN echo "daemon off;" >>/etc/nginx/nginx.conf
- ADD index.html /usr/share/nginx/html/index.html
- EXPOSE 80
- CMD ["nginx"]
- [ dockerfile]# cat index.html
- hello liuhx
- [ dockerfile]# pwd
- /root/dockerfile
- [ dockerfile]#
构建镜像
- cd /root/dockerfile
- Docker build -t mynginx/mynginx03:03 ./
- [ dockerfile]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- mynginx/mynginx03 v3 8c81f51923e5 2 minutes ago 374.6 MB
启动容器:
- [ dockerfile]# docker run -d --name nginx007 -p 86:80 mynginx/mynginx03:v3
- 6f2501177ac00e064b22c6c3045b973dc41935e82180753a21a14f3224f5f323
来源: