1、Dockerfile指令构建jdk
1、创建目录
[root@VM_190_147_centos ~]# mkdir -p /usr/local/dockerjdk8
2、下载jdk-8u171-linux-x64.tar.gz并上传到服务器中的/usr/local/dockerjdk8目录
3、创建Dockerfile文件
[root@VM_190_147_centos dockerjdk8]# vim Dockerfile
#依赖镜像名称和ID
FROM centos:7
#指定镜像创建者信息
MAINTAINER ITCAST
#切换工作目录
WORKDIR /usr
RUN mkdir /usr/local/java
#ADD 是相对路径jar,把java添加到容器中
ADD jdk-8u171-linux-x64.tar.gz /usr/local/java/
#配置java环境变量
ENV JAVA_HOME /usr/local/java/jdk1.8.0_171
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH
4、构建
[root@VM_190_147_centos dockerjdk8]# docker build -t jdk1.8 -f ./Dockerfile .
5、启动容器
[root@VM_190_147_centos dockerjdk8]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jdk1.8 latest 5e1d02ea7b37 2 minutes ago 588MB
2、Dockerfile指令构建nginx
1、第一步:我们从官网下载nginx1.14.1.gz版本的nginx,把该文件及nginx.config文件上传至目录/opt/my_dockerfile/nginx。
[root@aliyun205 nginx]# pwd
/opt/my_dockerfile/nginx
[root@aliyun205 nginx]# ls
nginx-1.14.1.gz nginx.conf
2、第二步:编辑Dockerfile文件
[root@aliyun205 nginx]# vim Dockerfile
FROM centos:7
MAINTAINER kefei@163.com
RUN yum install -y gcc gcc-c++ make openssl-devel pcre-devel
ADD nginx-1.14.1.gz /tmp
RUN cd /tmp/nginx-1.14.1 && \
./configure --prefix=/usr/local/nginx && \
make -j 2 && \
make install
RUN rm -rf /tmp/nginx-1.14.1* && yum clean all
COPY nginx.conf /usr/local/nginx/conf
WORKDIR /usr/local/nginx
EXPOSE 80
CMD ["./sbin/nginx", "-g", "daemon off;"]
3、构建镜像
#构建docker镜像
[root@aliyun205 nginx]# docker build -t nginx/v1 -f /opt/my_dockerfile/nginx/Dockerfile .
---> 4d588af208b2
Step 7/10 : COPY nginx.conf /usr/local/nginx/conf
---> cab2c1c73a9a
Step 8/10 : WORKDIR /usr/local/nginx
---> Running in 801613f705c7
Removing intermediate container 801613f705c7
---> 94ce54d3573c
Step 9/10 : EXPOSE 80
---> Running in eafb05bca0b1
Removing intermediate container eafb05bca0b1
---> 7c274508e263
Step 10/10 : CMD ["./sbin/nginx", "-g", "daemon off;"]
---> Running in bf175eabe49c
Removing intermediate container bf175eabe49c
---> cf318195e70a
Successfully built cf318195e70a
Successfully tagged nginx/v1:latest