I'm having difficulty using liquibase at build time to create my schema and seed the database in an image that extends the mysql 5.7 base image. Specifically, I'm receiving a timeout because I can't connect to my database within the same singular image.
The last line in the Dockerfile below will not execute. I get the error:
Starting Liquibase at Thu, 16 May 2019 22:09:50 UTC (version 3.6.3 built at 2019-01-29 11:34:48)
Unexpected error running Liquibase: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
...
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
... 12 common frames omitted
FROM mysql:5.7
ENV MYSQL_DATABASE dbname
# Install wget, jdk, liquibase, mysql connector/j
...
RUN liquibase --changeLogFile=/path/to/script/schema.mysql.sql \
--username=root \
--password=password \
--url=jdbc:mysql://localhost:3306/dbname" \
--driver=com.mysql.cj.jdbc.Driver \
--classpath=/path/to/liquibase/liquibase.jar:/path/to/mysql-connector/mysql-connector-java-8.0.16.jar \
--contexts="Initialization" \
update
I'd expect for the sql script to execute to create my database schema.