Dockerfile的使用
简介
制作docker镜像可以通过修改容器的方式,也通过通过Dockerfile文件的方式,下面通过Dockerfile文件的例子进行说明。
Dockerfile文件
FROM openjdk:8-alpine
#ENV http_proxy http://127.0.0.1:7890
#ENV https_proxy http://127.0.0.1:7890
#ENV TZ=Asia/Shanghai
#RUN set -eux; \
# ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
# echo $TZ > /etc/timezone
#RUN apk update \
# && apk upgrade \
# && apk add --no-cache bash \
# bash-doc \
# bash-completion \
# && rm -rf /var/cache/apk/* \
# && /bin/bash
#RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN echo "http://mirrors.ustc.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN cat /etc/apk/repositories
# 容器内执行
#$RUN rm -fr /var/cache/apk
#RUN mkdir -p mkdir /var/cache/apk
RUN rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
RUN apk update
ENV TZ=Asia/Shanghai
RUN set -eux; \
apk add --no-cache tzdata; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
echo $TZ > /etc/timezone
#RUN apk update \
# && DEBIAN_FRONTEND=noninteractive apt install -y tzdata \
# && rm -rf /var/lib/apt/lists/*
RUN set -eux; \
addgroup --gid 1000 java-app; \
adduser -S -u 1000 -g java-app -h /home/java-app/ -s /bin/sh -D java-app;
EXPOSE 8080
COPY --chown=java-app firefly /home/java-app/firefly
ADD docker-entrypoint.sh /home/java-app/firefly/docker-entrypoint.sh
RUN chown -R java-app:java-app /home/java-app
USER java-app
WORKDIR /home/java-app/firefly
CMD /home/java-app/firefly/docker-entrypoint.sh
精简的Dockerfile文件
FROM openjdk:8-alpine
RUN echo "http://mirrors.ustc.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN cat /etc/apk/repositories
RUN rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
RUN apk update -v
ENV TZ=Asia/Shanghai
RUN set -eux; \
apk add --no-cache tzdata; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
echo $TZ > /etc/timezone
RUN set -eux; \
addgroup --gid 1000 java-app; \
adduser -S -u 1000 -g java-app -h /home/java-app/ -s /bin/sh -D java-app;
EXPOSE 8080
COPY --chown=java-app firefly /home/java-app/firefly
ADD docker-entrypoint.sh /home/java-app/firefly/docker-entrypoint.sh
RUN chown -R java-app:java-app /home/java-app
USER java-app
WORKDIR /home/java-app/firefly
CMD /home/java-app/firefly/docker-entrypoint.sh
制作镜像命令脚本
#!/bin/bash
image=harbor.k8s/firefly/firefly-spring-boot-starter:1.2.0
#docker build -t $image ./ --build-arg HTTP_PROXY="http://127.0.0.1:7890" --no-cache
docker build -t $image ./ --no-cache
#--network=host
#docker build -t $image ./ --progress=plain --no-cache
#docker push $image