apt install openjdk-8-jdk
我使用Ubuntu20.04,默认是Java 11,需要切换到Java 8,参考这里
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /opt/mysql/:/var/lib/mysql -d mysql:5.7
git clone https://github.com/j3ers3/Hello-Java-Sec.git
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test
spring.datasource.username=root
spring.datasource.password=123456
root@l-virtual-machine:/opt/Hello-Java-Sec# mysql -uroot -p123456 -h127.0.0.1
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed
mysql> source /opt/Hello-Java-Sec/src/main/resources/db.sql
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.02 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mvn clean package -DskipTests
FROM openjdk:8
RUN apt update -y
RUN apt install -y maven
COPY . /opt/seccode/
WORKDIR /opt/seccode
RUN mvn clean package -DskipTests
ENTRYPOINT java -jar target/javasec-1.10.jar
version: '2'
services:
seccode:
build:
context: /opt/Hello-Java-Sec/
dockerfile: Dockerfile
image: seccode
networks:
extnetwork:
ipv4_address: 172.20.0.100
ports:
- 8888:8888
environment:
MYSQL_USER: root
MYSQL_PASSWORD: 123456
db:
image: mysql:5.7
networks:
extnetwork:
ipv4_address: 172.20.0.200
container_name: db
volumes:
- ./data/mysql:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: jxwaf
MYSQL_USER:
MYSQL_PASSWORD:
user: root
privileged: true
networks:
extnetwork:
ipam:
driver: bright
config:
- subnet: 172.20.0.0/16
gateway: 172.20.0.1
docker-compose build
docker-compose up
java -jar target/javasec-1.10.jar