[容器]docker创建镜像

手动创建:

docker run -d -p mynginx:v2 nginx
rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
yum install nginx -y
vi /etc/nginx/nginx.conf
daemon off;
docker ps -a
docker commit a823e15f958b oldboyedu/mynginx:v3
docker run -d -p 80:80 oldboyedu/mynginx:v3 nginx

 

用Dockerfile创建:

mkdir -p /opt/dockerfile/nginx
echo '<h1>test index</h1>' > index.html
[root@lanny nginx]# cat Dockerfile 
FROM centos
MAINTAINER lanny.ma iher@foxmail.com
WORKDIR /etc/yum.repos.d/
ADD CentOS-Base.repo /etc/yum.repos.d/
RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install nginx -y
WORKDIR /etc/nginx
RUN echo 'daemon off;' >> /etc/nginx/nginx.conf
ADD index.html /usr/share/nginx/html
VOLUME ["/etc/nginx"]
VOLUME ["/usr/share/nginx/html"]
VOLUME ["/var/www"]
EXPOSE 80 443
CMD ["nginx"]
docker build -t oldboyedu/mynginx:v4 /opt/dockerfile/nginx/
docker run -d -p 80:80 oldboyedu/mynginx:v4
docker ps -a

 

posted @ 2016-11-21 11:56  _毛台  阅读(334)  评论(0编辑  收藏  举报