source.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverseDockerfile
FROM ubuntu:xenial # 环境 COPY sources.list /etc/apt/sources.list RUN apt-get update --fix-missing -y && apt-get update -y # JAVA环境 RUN apt-get install -y openjdk-8-jdk apt-transport-https # 项目 WORKDIR /proj ADD generator-web-2.0.jar app.jar # ENV ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ENV LANG C.UTF-8 ENTRYPOINT ["java", "-jar", "app.jar"]运行Dockerfile
$ docker build -t myapp -f Dockerfile . $ docker image ls | grep myapp 创建docker-compose.yml文件 version: "3.4" x-logging: &default-logging driver: json-file options: max-size: '5m' max-file: '10' services: app: image: myapp:latest container_name: myapp ports: - 12345:12345 restart: always logging: *default-logging启动
$ docker-compose -f docker-compose.yml up项目结构如下: