1、下载jdk1.8
下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
我下载的是jdk1.8.0_191
2、上传到服务器,并解压
3、在解压jdk1.8.0_191的同级目录新建一个Dockerfile文件,内容如下:
vim Dockerfile
FROM centos:7
MAINTAINER kongchen
ADD jdk1.8.0_191 /opt/jdk8
ENV JAVA_HOME /opt/jdk8
ENV PATH $JAVA_HOME/bin:$PATH
# Install necessary tools
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
# Install Nginx
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar zxvf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install
dockerfile文件内容详解:
FROM centos:7 表示选择centos7作为基础镜像
MAINTAINER kongchen 表示docker镜像的作者是kongchen
ADD jdk1.8.0_191 /opt/jdk8 表示将jdk1.8.0_191复制到容器的 /opt/jdk8目录
ENV 用于配置环境变量
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel 这一行是用yum的方式安装nginx的相关依赖
ADDhttp://nginx.org/download/nginx-1.8.0.tar.gz. 表示远程下载nginx安装包到本地
RUN tar zxvf nginx-1.8.0.tar.gz 表示解压nginx安装包
RUN mkdir -p /usr/local/nginx 创建路径
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install 编译并安装nginx
4、运行安装命令
docker build -t jdk:8 .
5、查看镜像
docker images
6、启动容器
//启动并进入容器
docker run -it -p 80:80 --name nginx jdk:8 /bin/bash
//启动nginx
cd /usr/local/nginx/sbin/
./nginx
网友评论