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