docker 镜像构建Dockerfile

3年前 (2017-06-09) gtj docker, 云计算 0评论 已收录 271℃

mkdir /opt/docker-file
cd/opt/docker-file/nginx
Dockerfile构建

docker build /opt/nginx/Dockerfile
怎么编写Dockerfile?
Dockerfile
基础镜像信息
维护者信息
镜像操作者指令
容器启动时执行指令

FROM :它的妈妈是谁(基础镜像)
MAINTAINER:告诉别人,谁创造了它(维护者信息)
RUN:你想让它干啥(把命令前面加上RUN)
ADD:往他肚子里放点文件(COPY文件,会自动解压)
WORKDIR:我是cd,今天刚化了妆(当前工作目录)
VOLUME:给我一个存放行李的地方(目录挂载)
EXPOSE:我要打开的门是啥(端口)

构建dockerfile 镜像

[root@docker-test nginx]# cat Dockerfile
## This is My first Dockerfile
# Vresion 1.0
## Author: jason ge
###
##base images
FROM centos
#Maintainer
MAINTAINER jason.zhao jason.zhao@oldboyedu.com

#ADD
ADD nginx-1.9.3.tar.gz /usr/local/src
ADD pcre-8.37.tar.gz /usr/local/src

#RUN
RUN yum install -y wget gcc gcc-c++ make openssl-devel
RUN useradd -s /sbin/nologin -M www

#WORKDIR
WORKDIR /usr/local/src/nginx-1.9.3
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=./../pcre-8.37 && make && make install

RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
ENV PATH /usr/local/nginx/sbin:$PATH

EXPOSE 80

CMD ["nginx"]

操作:
docker build -t nginx-file:v1(名字加版本号) /opt/docker-file/nginx/(dockerfile路径)

操作结果如下:
[root@docker-test nginx]# docker build -t nginx-file:v1 /opt/docker-file/nginx/
Sending build context to Docker daemon 2.91 MB
Step 1 : FROM centos
---> 98d35105a391
Step 2 : MAINTAINER jason.zhao jason.zhao@oldboyedu.com
---> Running in 8a3f60020aa3
---> f93924f5bce3
Removing intermediate container 8a3f60020aa3
Step 3 : ADD nginx-1.9.3.tar.gz /usr/local/src
---> 140b7e91fabc
Removing intermediate container b51849b6b39f
Step 4 : ADD pcre-8.37.tar.gz /usr/local/src
---> f9956bafe440
Removing intermediate container 098f3d46a5eb
Step 5 : RUN yum install -y wget gcc gcc-c++ make openssl-devel
---> Running in 330cdda025b1
Loaded plugins: fastestmirror, ovl
结果:
[root@docker-test nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-file v1 4dbde8f9476a About a minute ago 387 MB

启动一个容器:
docker run -d -p 97:80 --name nginxd nginx-file:v1

docker ps 查看正在运行的容器。

博主

这货来去如风,什么鬼都没留下!!!

相关推荐

嗨、骚年、快来消灭0回复。

×
订阅图标按钮
Less is more!!!