Reputation: 15719
I'm trying to create a Docker installation of Jahia CMS (Digital Experience Manager).
I need :
The trick is that during the Jahia container build (product installation using Expect), I need to access the MySQL container (connection check required).
MySQL Dockerfile :
FROM mysql:5.6
Jahia Dockefile :
FROM centos:centos6
# Install dependencies
RUN yum -y update && yum -y install ...
# Download Digital Experience Manager 7.1.1
RUN wget -q https://www.jahia.com/downloads/jahia/digitalexperiencemanager7.1.1/DigitalExperienceManager-EnterpriseDistribution-7.1.1.0-r53717.3663.jar -O /tmp/DigitalExperienceManager.jar
# Download MySQL connector (only needed for standalone db installation)
RUN wget -q http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar -O /usr/lib/mysql-connector-java-5.1.44.jar
# Launch installation using Expect to automate user input
COPY jahia_conf.exp /tmp/configuration.exp
RUN expect /tmp/configuration.exp
# Start Jahia
/opt/DigitalExperienceManager-EnterpriseDistribution-7.1.1.0/tomcat/bin/catalina.sh jpda run
Expect script (jahia_conf.exp)
#!/bin/sh
#!/usr/bin/expect
spawn java -jar /tmp/DigitalExperienceManager.jar -console
# Installation directory
expect "Select target path"
send "/opt/DigitalExperienceManager-EnterpriseDistribution-7.1.1.0\r"
# MySQL connector JAR file
expect "Specify the path to the downloaded driver JAR file"
send "/usr/lib/mysql-connector-java-5.1.44.jar\r"
# Database configuration
expect "Database URL (*)"
send "jdbc:mysql://mysql:3306/jahia?useUnicode=true&characterEncoding=UTF-8&useServerPrepStmts=false\r"
Of course I get an error during image build because it checks the connection right after database URL input :
An error occurred while establishing the connection to the database com.mysql.jdbc.exceptions.jdbc4.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..
Indeed I'm just building the Jahia image, so the mysql
container is not yet accessible (even if running).
How to deal with this kind of situation (when you need to access another container during build) ?
Upvotes: 0
Views: 936
Reputation: 11
As MySQL server will also be in a container, I don't think you should configure it at build time, as you can't assume the database will be up.
Unfortunately, i don't know how 'expect' tool works, but ideally you should link the Database in Jahia container only at container startup. This can be done by injecting it through configuration (environment variable or something else you can inject when you start the container)
That means the MySQL container should have the DB installed in a separated process. On our side for example, we do this by running the sql scripted provided in jahia code directly on the database.
With this solution, you ensure that you don't need your database preinstalled while building.
edit: indeed, Jahia is doing some checks on the database at build time, but you can add an input so Jahia doesn't actually need to perform operation on the DB. It uses izpack autoplay file. That allows to replay the installation.
The DB setup part is the following:
<com.izforge.izpack.panels.UserInputPanel id="dbSettings">
<userInput>
<entry key="dbSettings.connection.url.mssql" value="jdbc:sqlserver://DB_SERVER;DatabaseName=DB_NAME;"/>
<entry key="dbSettings.dbms.createTables" value="false"/>
<entry key="dbSettings.connection.username" value="DB_USER"/>
<entry key="dbSettings.dbms.storeFilesInDB" value="false"/>
<entry key="dbSettings.connection.driver.mssql" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<entry key="dbSettings.connection.password" value="DB_PASSWORD"/>
</userInput>
</com.izforge.izpack.panels.UserInputPanel>
This assume you have a DB server somewhere unfortunately. On our side we use a fake instance as we request not doing the installation during the build.
Upvotes: 1
Reputation: 4677
Try using docker commit. You may have to run the configuration.exp
script to set up Jahia by exec'ing into your container. Then use docker commit to save the changes to the file system into a new image. That image should persist the initial configuration.
Be mindful that volumes are not included in a docker commit, as they live outside Docker's union file system. It doesn't look like you're declaring any volumes in your Dockerfile, so it probably won't be a problem for you. This answer elaborates on docker commit and database volumes, but the premise is the same for any container.
Upvotes: 0