I am new in docker but my requirement is to create a docker file to run my java application (.jar file) which have connected with mysql.
My Docker file is :
FROM openjdk:8
MAINTAINER XYZ
ENV HOME /home/springboot
WORKDIR /home/springboot/sample
ADD target/springbootmysql-0.0.1-SNAPSHOT.jar springbootmysql.jar
CMD ["java", "-jar", "springbootmysql.jar"]
FROM mysql:5.7
ENV MYSQL_USER=USER1
ENV MYSQL_PASSWORD=user@123
ENV MYSQL_DATABASE="test_db" \
MYSQL_DATA_DIR=/var/lib/mysql \
MYSQL_RUN_DIR=/run/mysqld \
MYSQL_LOG_DIR=/var/log/mysql
#USER root
COPY mysqldemo.sql /docker-entrypoint-initdb.d/
RUN /etc/init.d/mysql start && mysql -u root -e "CREATE USER $MYSQL_USER@'localhost' IDENTIFIED BY 'global@123';GRANT ALL PRIVILEGES ON *.* TO $MYSQL_USER@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;" && mysql -u $MYSQL_USER -p 'global@123' $MYSQL_DATABASE < /docker-entrypoint-initdb.d/mysqldemo.sql
EXPOSE 9999 3306/tcp
after running following commands over docker -
$docker build . -t sample:1
It successfully created the image file .
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 049063703a96 A minute ago 372MB
<none> <none> 735cd7af5738 A minute ago 757MB
mysql 5.7 0164c13b662c 6 days ago 372MB
openjdk 8 891c9734d5ab 5 weeks ago 726MB
sample image is not showing …??
As per the requirement need to create a single dockerfile which will manage build all the required images and finally we can able run our project.