【docker镜像】记录自用的dockerfile文件和打包命令

一、Dockerfile

jar包指令

小区管理(有些不能用)

## 设置本镜像需要使用的基础镜像
#FROM openjdk:8-jre
#  
## 把jar包添加到镜像中
#ADD xiaoquguanli.jar /xiaoquguanli.jar
#
# #WORKDIR指令用于指定容器的一个目录, 容器启动时执行的命令会在该目录下执行。
#WORKDIR /opt/docker/images/xiaoquguanli/
#
## 镜像暴露的端口
#EXPOSE 8091
# 
##RUN bash -c 'touch /xiaoquguanli.jar'
#  
## 容器启动命令
##ENTRYPOINT ["java","-jar","/xiaoquguanli.jar"]
#CMD java -jar xiaoquguanli.jar
# 
## 设置时区
##RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
#

 #2能生成镜像
#FROM gmaslowski/jdk:8
#CMD ["/bin/sh","-c","mkdir","-p","/opt/AAA"]
#ADD xiaoquguanli.jar /opt/AAA/xiaoquguanli.jar
#ENTRYPOINT ["java","-jar","/opt/AAA/xiaoquguanli.jar"]


# 3基于哪个镜像,需要用一个已有的镜像做载体来创建,这里我使用的java8镜像,如果大家的docker镜像中没有java8,它就会自动去下载
FROM kdvolder/jdk8

# 将本地文件夹挂载到当前容器,指定/tmp目录并持久化到Docker数据文件夹,因为Spring Boot使用的内嵌Tomcat容器默认使用/tmp作为工作目录
VOLUME /tmp

# 添加自己的项目到 system.jar中   这里我是取了system.jar的名字,这个名字可以随便取的,只要后面几行名字和这个统一就好了
ADD xiaoquguanli.jar /xiaoquguanli.jar

# 开放8888端口
EXPOSE 8091

# ENTRYPOINT指定容器运行后默认执行的命令
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/xiaoquguanli.jar"]
#ENTRYPOINT ["java","-jar","xiaoquguanli.jar","--spring.profiles.active=local"]

和工程

#java8环境
FROM java8
#暴露端口
EXPOSE 8888

#将项目JAR包
VOLUME /apps
#COPY ./application.yml /tmp/application.yml
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/apps/devel-server-start-1.0.0.jar"]
# ENTRYPOINT java -jar /tmp/devel-server-start-1.0.0.jar

二网

FROM openjdk:8-jdk-alpine

# 设置时区
ENV TZ=Asia/Shanghai
# 时区写入系统文件
RUN ln -snf /usr/share/zoneinfo/$TZ  /etc/localtime && echo $TZ > /etc/timezone
#COPY ./target/eova-pro-release.zip /eova-pro-release.zip
#RUN unzip eova-pro-release.zip
COPY ./eova-pro-release /eova-pro-release
RUN chmod +x ./eova-pro-release/eova.sh
ENV ACTIVE_PARAMS=""
ENTRYPOINT ["./eova-pro-release/eova.sh","start"]

二、dist包指令

#proplatform docker file
FROM nginx:latest
MAINTAINER gyf
#RUN rm -v /etc/nginx/nginx.conf
RUN rm -r /etc/nginx/conf.d/
RUN rm -r /usr/share/nginx/html/
#ADD nginx.conf /etc/nginx/
ADD conf.d/ /etc/nginx/conf.d/
ADD html/ /usr/share/nginx/html/
EXPOSE 80
ENTRYPOINT nginx -g "daemon off;"

front项目

FROM nginx:latest
MAINTAINER gyf
#RUN rm -v /etc/nginx/nginx.conf
RUN rm -r /etc/nginx/conf.d/
RUN rm -r /usr/share/nginx/html/
#ADD nginx.conf /etc/nginx/
ADD conf.d/ /etc/nginx/conf.d/
ADD html/ /usr/share/nginx/html/
EXPOSE 80
ENTRYPOINT nginx -g "daemon off;"

自己用的镜像打包命令

jar包打包

#打包镜像
docker build -f dockerfile -t xiaoquguanli:1.1 .
#强制删除容器
docker rm -f xiaoquguanli
#运行镜像
docker run -d -p 8090:8091 --name="xiaoquguanli" xiaoquguanli:1.1
#修改镜像自启
docker update xiaoquguanli --restart always

dist包打包

#强制删除容器
docker rm -f guanli1.0
#删除镜像
docker rmi guanli:1.0
#镜像打包
docker build -t guanli:1.0 .
#运行镜像
#不能用
#docker run -d --privileged=true --name guanli1.0 --restart always --net=host guanli:1.0
#能用
docker run -d --privileged=true --name guanli1.0 -p 8080:80 --restart always guanli:1.0

nginx配置文件

nginx.config(默认)


user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

default.conf(默认)

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值