dockerfile
实例1
[root@lab2 docker-file]# cd server1/
[root@lab2 server1]# ls
a.sh ddbes-server1-0.0.1-SNAPSHOT.jar Dockerfile
[root@lab2 docker-file]# cat server1/Dockerfile
FROM java:8-jre-alpine
COPY ddbes-server1-0.0.1-SNAPSHOT.jar /opt/docker-file/server1/ddbes-server1-0.0.1-SNAPSHOT.jar
WORKDIR /opt/docker-file/server1
EXPOSE 8881
CMD ["java", "-jar", "ddbes-server1-0.0.1-SNAPSHOT.jar"]
[root@lab2 server1]# docker build -t server1 /opt/docker-file/server1/
实例2、
[root@lab2 docker-file]# cd server2/
[root@lab2 server2]# ls
ddbes-server2-0.0.1-SNAPSHOT.jar Dockerfile
[root@lab2 server2]# cat Dockerfile
FROM java:8-jre-alpine
COPY ddbes-server2-0.0.1-SNAPSHOT.jar /opt/docker-file/server2/ddbes-server2-0.0.1-SNAPSHOT.jar
WORKDIR /opt/docker-file/server2
EXPOSE 8882
CMD ["java", "-jar", "ddbes-server2-0.0.1-SNAPSHOT.jar"]
[root@lab2 server2]# docker build -t server2 /opt/docker-file/server2/
实例3、
[root@ecs-8ee4 tomcat]# ls
apache-tomcat-8.5.31.tar.gz Dockerfile jdk-8u171-linux-x64.tar.gz ssoserver.war
[root@ecs-8ee4 tomcat]# cat Dockerfile
from centos
ADD apache-tomcat-8.5.31.tar.gz /usr/local
ADD jdk-8u171-linux-x64.tar.gz /usr/local
COPY hiteamDDBES.war /usr/local/apache-tomcat-8.5.31/webapps/
#set environment variable
ENV JAVA_HOME /usr/local/jdk1.8.0_171
ENV PATH $JAVA_HOME/bin:$PATH
EXPOSE 8080
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
#define entry point which will be run first when the container starts up
ENTRYPOINT /usr/local/apache-tomcat-8.5.31/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.31/logs/catalina.out
[root@ecs-8ee4 tomcat]# docker build -t ceshi .
[root@ecs-8ee4 tomcat]# docker tag ceshi 114.116.65.232:5000/library/ceshi/latest:v$BUILD_NUMBER
[root@ecs-8ee4 tomcat]#
[root@ecs-8ee4 tomcat]#
[root@ecs-8ee4 tomcat]# docker run -d -p 8085:8080 --restart=always --name ceshi 114.116.65.232:5000/library/ceshi/latest:v$BUILD_NUMBER
访问:养成带上绝对路径的习惯,否则总是访问到tomcat的首页
http://114.116.65.232:8085/ssoserver/
使用Dockerfile搭建jdk、tomcat运行环境
https://blog.csdn.net/yjk13703623757/article/details/68944549
https://blog.csdn.net/qq_24557827/article/details/73729913
注意:不能先解压安装包,这样虽然能打包,但是在k8s里面不显示
[root@host-10-1-1-71 dandang]# cat Dockerfile
FROM centos
ADD apache-tomcat-8.5.31.tar.gz /usr/local
ADD jdk-8u171-linux-x64.tar.gz /usr/local
COPY hiteamDDBES.war /usr/local/apache-tomcat-8.5.31/webapps/
#set environment variable
ENV JAVA_HOME /usr/local/jdk1.8.0_171
ENV PATH $JAVA_HOME/bin:$PATH
EXPOSE 8080
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
#define entry point which will be run first when the container starts up
ENTRYPOINT /usr/local/apache-tomcat-8.5.31/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.31/logs/catalina.out
[root@host-10-1-1-71 dandang]# docker build -t dandang:v1 .
访问:
使用jenkins镜像-1.142 制作带maven、jdk镜像, 不要单独制作jenkins镜像,试过多次没有成功,要用现成的jenkins镜像
[root@kube-node3 ~]# cat jenkins-dockerfile/Dockerfile
FROM jenkins/jenkins
ADD apache-maven-3.5.4-bin.tar.gz /usr/local/
ENV MAVEN_HOME=/usr/local/apache-maven-3.5.4
ENV PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
USER root
RUN apt-get update \
&& apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
USER jenkins
Dockerfile构建dicker镜像
[root@bogon ~]# mkdir /opt/docker-file
[root@bogon ~]# cd /opt/docker-file/
[root@bogon docker-file]# mkdir nginx
[root@bogon docker-file]# cd nginx/
[root@bogon nginx]# wget http://nginx.org/download/nginx-1.9.9.tar.gz
[root@bogon nginx]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz
[root@bogon nginx]# vi Dockerfile #必须大写
#this is my dockerfile
#verion 1.0
#auther zi hao
#Base imags
FROM centos :默认从本地
#MAINTAINER
MAINTAINER zi hao
#ADD
ADD pcre-8.42.tar.gz /usr/local/src
ADD nginx-1.9.9.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.9
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.42 && make && make install
RUN echo "daemon off;" >> /usr/local/nginx/nginx.conf
ENV PATH /usr/local/ngix/sbin:$PATH
EXPOSE 80
CMD ["nginx"]
dockerfile中设置环境变量
设置环境变量要用 ENV
ENV JAVA_HOME /usr/local/jdk1.8.0_171
ENV PATH $JAVA_HOME/bin:$PATH
用 echo "JAVA_HOME /usr/local/jdk1.8.0_171" >> /etc/profile 就出错,弄的好苦,之前一直出错,弄了一天,
后来改成 ENV 就好了
注意:
设置环境变量要用 ENV
ENV JAVA_HOME /usr/local/jdk1.8.0_171
ENV PATH $JAVA_HOME/bin:$PATH
用 echo "JAVA_HOME /usr/local/jdk1.8.0_171" >> /etc/profile 就出错,弄的好苦,之前一直出错,弄了一天,
后来改成 ENV 就好了