Run Wildfly Together With Postgresql Inward Docker

Docker is a dandy tool to copy a evolution environment. Not precisely that but it also makes that environs portable yesteryear having a docker/docker-compose configuration file. And that is what this weblog is all about.

We volition launch a pre-configured docker environment. This environs is your typical web-app amongst database access. In improver to that, nosotros volition also include an icon for logging, database, as well as keycloak inwards instance nosotros require an authentication server.

Let's boot the bucket through the configuration files as well as create from the original docker compose config. This configuration is responsible for edifice as well as starting all our images inwards the right order.

version: '3' services:     postgres:         image: postgres:10         container_name: postgres         ports:           - "5432:5432"         environment:             - LC_ALL=C.UTF-8             - POSTGRES_DB=terawhars             - POSTGRES_USER=terawhars             - POSTGRES_PASSWORD=terawhars             - POSTGRES_PORT=5432         volumes:             - $PWD/input_files/import-postgres.sql:/docker-entrypoint-initdb.d/import-postgres.sql             - $PWD/output_files/postgres_data:/var/lib/postgresql/data     adminer:         image: adminer         container_name: adminer         depends_on:             - postgres         ports:             - 8081:8080     wildfly:         image: terawhars         container_name: wildfly         build: .         ports:             - "8080:8080"             - "9990:9990"         environment:             - DB_HOST=postgres             - DB_PORT=5432             - DB_NAME=terawhars             - DB_USER=terawhars             - DB_PASS=terawhars             - DS_NAME=TeraWHARSDS             - JNDI_NAME=java:jboss/datasources/TeraWHARSDS         depends_on:             - postgres         volumes:             - $PWD/output_files/logs:/opt/jboss/wildfly/standalone/log             - $PWD/output_files/terawharsdata:/opt/jboss/wildfly/terawharsdata             - jboss-conf:/opt/jboss/wildfly/standalone/configuration     keycloak:         image: jboss/keycloak:4.0.0.Final         container_name: keycloak         ports:             - "8083:8080"         environment:             - DB_VENDOR=POSTGRES             - DB_ADDR=postgres             - DB_DATABASE=terawhars             - DB_USER=terawhars             - DB_PASSWORD=terawhars             - KEYCLOAK_USER=admin             - KEYCLOAK_PASSWORD=admin         depends_on:             - postgres     weblogs:         image: opencell/alpine-tailon         container_name: tailon         depends_on:             - wildfly         ports:             - 8082:8080         volumes:             - $PWD/output_files/logs:/logs/ volumes:     jboss-conf: {} 
This configuration installs Postgresql, Adminer, Tailon, Wildfly, Keycloak. For a to a greater extent than detailed didactics on what each plain means, delight consult the Docker documentation, we're non hither to learn that.

Things to convey authorities notation of:

  • You require to create the folder specified inwards the volumes. It volition re-create the files from docker container to your local machine. For docker to practice that, you lot require to portion your campaign (Windows).
  • Don't role the same local port for dissimilar images.
  • Notice that nosotros role a unmarried database for Keycloak as well as the Web app/Wildfly, spell nosotros tin role some other icon that allows multiple databases, it's easier this way. The downside is all the tables volition live on created on a unmarried database for both Keycloak as well as our Web app.
Most of the icon nosotros role precisely requires minimal configuration similar inwards Postgres, nosotros precisely require to define the database configuration. It could boot the bucket to a greater extent than complicated if nosotros require to practice replication, etc. But I recall our illustration is plenty for this tutorial. Now the icon that requires some to a greater extent than piddling is our spider web app since nosotros require to configure the information source as well as download the nation of war file.
FROM jboss/wildfly:13.0.0.Final  LABEL com.terawhars.version="0.0.1-snapshot" LABEL author="Edward P. Legaspi" LABEL email="czetsuya@gmail.com" LABEL vendor1="TeraWHARS" LABEL com.terawhars.release-date="2018-07-24"  # Set Postgresql env variables ENV DB_HOST postgres ENV DB_PORT 5432 ENV DB_NAME terawhars ENV DB_USER terawhars ENV DB_PASS terawhars  ENV DS_NAME TeraWHARSDS ENV JNDI_NAME java:jboss/datasources/TeraWHARSDS  USER source  ADD https://jdbc.postgresql.org/download/postgresql-42.2.4.jar /tmp/postgresql-42.2.4.jar  WORKDIR /tmp COPY input_files/wildfly-command.sh ./ COPY input_files/module-install.cli ./ RUN sed -i -e 's/\r$//' ./wildfly-command.sh RUN chmod +x ./wildfly-command.sh RUN ./wildfly-command.sh \     &&  rm -rf $JBOSS_HOME/standalone/configuration/standalone_xml_history/  # Download as well as deploy the nation of war file ADD https://github.com/czetsuya/javaee6-docker-web/releases/download/1.0.0/javaee6-webapp.war $JBOSS_HOME/standalone/deployments  # Create Wildfly admin user RUN $JBOSS_HOME/bin/add-user.sh admin admin --silent  # Set the default ascendency to run on boot # This volition boot WildFly inwards the standalone vogue as well as bind to all interface CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"] 

What it does:

  • Download PostgreSQL driver
  • Setup information source
  • Download the nation of war file inwards Wildfly's deployment directory
  • Create a default admin user
  • Note that for this exceptional example, nosotros are using the standalone.xml WF configuration
Some other things to convey note:
  • For PostgreSQL, the icon nosotros specified an SQL file that volition live on imported on startup. This volition initialize our database.
  • We role a .env file to define the PWD variable that is non acquaint inwards Windows.
To run into how it industrial plant banking corporation jibe out the consummate code from https://github.com/czetsuya/Docker-Demo as well as and thus run:
>docker-compose upwards --build

It volition convey some fourth dimension during the offset run equally it volition download all the images locally first.

References:
I convey customization chore for a minimum fee of $50, thus don't hesitate to contact me when your lazy to endeavor something :-)
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.