Setting custom system-property for Payara Docker image - docker

I am new to Docker and trying to create a Payara image for my application.
In that, I need to set a bunch of custom system-properties as server configs...like I have them in my Payara domain.xml:
<configs>
<config name="server-config">
<system-property name="com.myorg.config.propertyA" value="abc"></system-property>
<system-property name="com.myorg.config.propertyB" value="def"></system-property>
.....
......
.......
So far, the Dockerfile I wrote, is like this.
I am trying to set just one system-property as of now, to experiment with ..and it's not working:
FROM payara/server-full
COPY myapp.war $DEPLOY_DIR
RUN echo 'set configs.config.server-config.system-property.com.myorg.config.propertyA=abc' > $POSTBOOT_COMMANDS
If I look at the post-boot-commands.asadmin inside the running container, it looks like this:
set configs.config.server-config.system-property.com.myorg.config.propertyA=abc
deploy /opt/payara/deployments/myapp.war
My application WAR ultimately fails to deploy due to being unable to find the property 'com.myorg.config.propertyA'.
I think I am trying to set the system property in the wrong way. Can anybody please advise? TIA

I found this works in the Dockerfile.
(So, I was trying to set it the wrong way initially).
RUN echo 'create-system-properties com.myorg.config.propertyA=abc' > $POSTBOOT_COMMANDS

Related

New Keycloak image with own changes crashes directly

I have a weird problem with Docker and hope someone here can help me :)
I want to create a keycloak image that is derived from the image jboss/keycloak. The idea is that in the Dockerfile also a preconfigured standalone.xml is copied into the image and keycloak can start directly without manual work.
But as soon as I write for example a
"CMD touch /opt/test.txt"
into the file the container crashes with the message "12:02:14,290 INFO [org.jboss.modules] (main) JBoss Modules version 1.9.1.Final
WFLYSRV0073: Invalid option '/bin/sh'"
This is just a new file with no purpose, the changes to the .xml are not in there yet.
As soon as I put only the FROM back in and rebuild everything works again.
I thought through the layers in the container you could mod an image, but here it doesn't seem to work. Can someone tell me why ?
So far it has always worked with the alpine image, but I don't want to build the whole keycloak setup again myself, when there is already an official image for it.
This is basically what I had in mind:
FROM jboss/keycloak:X.XX
CMD rm /opt/jboss/keycloak/standalone/configuration/standalone.xml
COPY ./keycloak/standalone.xml /opt/jboss/keycloak/standalone/configuration/
Thanks for help :)
Change
CMD rm
to
RUN rm
RUN is part of building. every RUN command is executed while your image is built.
With CMD you define (or override) the default command when running/starting a container based on your image (and you don't want to change keycloaks default CMD)

How to make environment variable visible to non root users inside the container?

I am trying to pass on environment variables to be read from an XML file inside a docker container running wildly app service and hosted inside REHL 7 image.
What I've done so far:
I've created an environment file as key value pair, for example: FILESERVICE_MAX_POOL_SIZE=5
I am running docker by referencing the environment file: docker run -d --env-file ./ENV_VARIABLES <myImage>
In the Dockerfile I copy the xml template I need: COPY dockerfiles/standalone.xml /opt/wildfly/standalone/configuration/standalone.xml
Inside the XML template I'm trying to reference the environment variable: <max-pool-size>${env.FILESERVICE_MAX_POOL_SIZE}</max-pool-size>
I can see those environment variables inside the running container as root but not as the wildly user which needs them. How can I make an attribute visible to a specific user other than root ?
Clearly I'm doing something fundamentally wrong here just not sure what ?
Thanks in advance for your help.
Problem solved: wildfly couldn't see the attributes because in my startup script I didn't add the -E flag for sudo to preserve environment variables.

How to add a custom environment variables to docker-ejabberd

I am running docker-ejabberd on ECS and all works fine. Now i want to replace the my_sql user/pass that exists on the ejabberd.yml file with the environment variables been passed to the image while running the container. There is no clear way described even on the docker-ejabberd wiki or anywhere on how to do that simply. Does anyone face a similar situation and how to do that?
For example in the ejabberd.yml i have this section:
sql_server: ${MYSQL_SERVER}
sql_database: ${MYSQL_DATABASE_NAME}
sql_username: ${MYSQL_USERNAME}
sql_password: ${MYSQL_PASSWORD}
sql_port: ${MYSQL_PORT}
I want to pass those vars as env vars while docker run and then replace them before the container run.
Side note: We are using ECS and passing the variables through the task defination without any issue.
I went through some topics recommend using the ENTRY_POINT command to run a script that replaces the file before running the container but not sure if that's a good idea.
Also, I have an idea of replacing the variables in this ejabberd.yml file in the CICD pipeline just before building the image and while getting the code from the git repository and create the image on AWS ECR?
i want to replace the my_sql user/pass that exists on the ejabberd.yml file with the environment variables been passed to the image while running the container.
The ejabberd.yml file is read and parsed by the yconf library (https://github.com/processone/yconf) , and I doubt it supports such a thing.
I went through some topics recommend using the ENTRY_POINT command to run a script that replaces the file before running the container but not sure if that's a good idea.
Following that recomendation, if you don't want to mess with the whole ejabberd.yml and let a script manipulate it, you can ensure that only those specific options are parametrized:
You can define those vars using a script in a small file, and then include options from that small file into ejabberd.yml using
https://docs.ejabberd.im/admin/configuration/file-format/#include-additional-files
For example, in your ejabberd.yml, put something like this:
include_config_file:
/etc/ejabberd/database.yml:
allow_only: [sql_server, sql_database, sql_username, sql_password, sql_port]
Then write your script, that generates that small file, for example:
$ generate-database-config.sh
$ cat /etc/ejabberd/database.yml
sql_server: "localhost"
sql_database: "ejaup"
sql_username: "ejabberd_test"
sql_password: "ejabberd_test"
sql_port: 3306

`docker service update` not working to update config

Firstly every step is done seemingly successfully (not any error reported). But per what I understand about how to check if the new config is applied OK, it seems to be failed updating the config.
Suppose I have a config file with a simple content like this:
Well done
I created a config (the first version) like this:
echo 'Well done' | docker config create my-config -
Now I have a local file named my-config.txt (on the host machine) with content as described above, it's used as a template (source) to clone over the target on the Docker container. On the Docker container, there is already a config file with the same content (originally). Now I change the content of the file my-config.txt (on the host machine) to something like this:
Well done !!!
And next I update the current docker service (created before) by using docker service update to apply the new config file, like this:
//firstly create another version of config
docker config create my-config-2 /home/my_user/my-config.txt
docker service update \
--config-add source=my-config-2,target=my-config.txt \
--config-rm my-config \
my-service
As I said, it seems to execute successfully. But when I try opening the my-config.txt file on the Docker container, its content is kept unchanged, like this:
docker exec [container_id] cat my-config.txt
It still shows Well done whereas the expected content should be Well done !!!. Isn't that what it should be? Am I doing something wrong here? Or could you suggest something to diagnose this issue or something different from what I've done without having to trying to solve this issue?

Docker - Changes to postfix's main.cf file are overriden on container start

I am trying to setup a dockerized Nagios. For that, I am using the already working image from jasonrivers: Dockerfile
Now, I need to slightly adjust the postfix, that is already installed in the image. I need to setup a relayhost so that e-mails that are sent from nagios are forwarded to my Mail-Server. Which should be as simple as setting the "relayhost" property in /etc/postfix/main.cf.
However, no matter how I adjust this value in my Dockerfile (I tried doing it with both sed and a COPY), when I inspect the /etc/postfix/main.cf file after starting the container the relayhost value was overridden to an empty value.
At first I thought that this has to do something with docker itself, I thought that somehow my steps in the Dockerfile that adjust this file did not end up affecting the final image. However, when I override main.cf with gibberish (like setting it's content to just "foo") then upon running the image, postfix throws some errors about it.
To put the words into code, consider this Dockerfile:
FROM jasonrivers/nagios:latest
RUN echo "relayhost = www.abc.com" > /etc/postfix/main.cf
Building this and then running the resulting image will result in a /etc/postfix/main.cf file with contents
relayhost =
I have tried using google to figure out how postfix works and why it does that, but the only suggestion I found was that something is configured in "master.cf", which it is not (you can download the image yourself and test all this yourself).
The JasonRivers/Docker-Nagios repo for the image has a feature in the postfix startup script to modify that setting overlay/etc/sv/postfix/run:
sed -i "s/relayhost =.*/relayhost = ${MAIL_RELAY_HOST}/" /etc/postfix/main.cf
Set the MAIL_RELAY_HOST environment variable to your host.
ENV MAIL_RELAY_HOST=www.abc.com

Resources