Docker 部署 Springboot 项目

tech2023-11-15  87

Docker 部署 Springboot 项目

下载docker $ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo apt-key fingerprint 0EBFCD88 $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli $ sudo gpasswd -a ${USER} docker $ sudo service docker restart 下载docker-compose $ sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose $ chmod a+x /usr/local/bin/docker-compose $ sudo chmod a+x /usr/local/bin/docker-compose $ docker-compose 创建Dockerfile并打包项目镜像

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 multiverse

Dockerfile

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

项目结构如下:

最新回复(0)