docker compose java,在docker-compose中运行Java

this is my docker-compose file.yaml:

version: '3.3'

services:

db:

container_name: dbContainer

image: mysql:5.7

volumes:

- /home/crismon-01/Documenti/TESI/Docker/mysqlLogin/datas:/var/lib/mysql

ports:

- 3306

environment:

MYSQL_ROOT_PASSWORD: "root"

MYSQL_USER: "root"

MYSQL_PASSWORD: "root"

MYSQL_DATABASE: "schema1"

java:

container_name: loginJava

image: openjdk:7

depends_on:

- db

volumes:

- ./home/crismon-01/Documenti/TESI/Docker/mysqlLogin:/usr/src/myapp

working_dir: /usr/src/myapp

command: bash -c "java -jar LogiIn.jar"

it is a compose with two cotnainer one with mysql and one with javacode that use the db, now i need to run it, and i have this error:

crismon-01@crismon01-XPS15:~/Documenti/TESI/Docker/mysqlLogin$ docker-compose up

Starting dbContainer ... done

Starting mysqllogin_java_1 ... done

Attaching to dbContainer, mysqllogin_java_1

dbContainer | Initializing database

dbContainer | 2018-04-12T15:35:07.134004Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

dbContainer | 2018-04-12T15:35:07.135231Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

dbContainer | 2018-04-12T15:35:07.135247Z 0 [ERROR] Aborting

dbContainer |

java_1 | Error: Unable to access jarfile LogiIn.jar

dbContainer exited with code 1

mysqllogin_java_1 exited with code 1

could someone have idea of the dource of error?

解决方案

The problem is that you are specifying command sections in the compose section of the java service. Only appears to be taken, which is the last one.

The solution is to group both commands into one command as such

java:

image: openjdk:7

depends_on:

- db

volumes:

- /home/crismon-01/Documenti/TESI/Docker/mysqlLogin:/usr/src/myapp

command: bash -c "cd /usr/src/myapp && java -jar LogiIn.jar"

Alternatively, you can only set working_dir property and remove the cd command.

volumes:

- /home/crismon-01/Documenti/TESI/Docker/mysqlLogin:/usr/src/myapp

working_dir: /usr/src/myapp

command: java -jar LogiIn.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值