1 SpringBoot微服务打包Docker镜像
1.1 构建springboot项目
package com.example.springboot.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
1.2 打包应用
本地cmd测试
java -jar demo-0.0.1-SNAPSHOT.jar
1.3 编写dockerfile
FROM java:8
COPY *.jar /app.jar
CMD ["--server.port=8080"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
上传文件:
- demo-0.0.1-SNAPSHOT.jar
- Dockerfile
1.4 构建镜像
docker build -t springboot-hello .
1.4 启动容器
docker run -d -P --name springboot-hello-web springboot-hello
curl localhost:49160/hello
2 部署python项目
2.1 创建项目
app.py
import time
import redis
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080, debug=True)
requirements.txt
flask
2.2 创建 dockerfile
# syntax=docker/dockerfile:1
FROM python:3.8-alpine
ADD . /code
WORKDIR /code
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
2.3 构建镜像
docker build -t py-test .
2.4 启动容器
docker run -d -p 8080:8080 --name py-test01 py-test