-1

I've a container which runs a java process via a jar file. (springboot application based)

My jar is using en vars from the container , thus my application.yml looks like this :

application.yml :

spring:
        profiles:
            active: server

        datasource:
            url: ${DATASOURCE_URL}
            databaseName: 
            serverName: 
            username: ${DATASOURCE_USERNAME}
            password: ${DATASOURCE_PASSWORD}
            dataSourceClassName: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
            registerMbeans: true
            maxPoolSize: ${DATASOURCE_MAXPOOLSIZE}
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
        data:
            couchbase:
                nodes: 
                    - ${COUCHBASE_NODE_1}
                    - ${COUCHBASE_NODE_2}
                bucket: ${COUCHBASE_BUCKET}
                password: ${COUCHBASE_PASSWORD}
                port: ${COUCHBASE_PORT}  

Where , DATASOURCE_USERNAME , DATASOURCE_PASSWORD ... are the env var of the container itself

My problem is where to define / declare thos variable , i ve tried to incldue it inside .bachrc , withinin a file , like this :

.bachrc :

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

########## CONFIGS FILES ############
source $HOME/envfile.list

and envfile.list look like this :

envfile.list:

DATASOURCE_USERNAME="aaa"
DATASOURCE_PASSWORD="bbb"
...

My pb is that my java process cannot see those variables , NOTE : i want to set those variables explicitlyt , without docker run -e

suggestions ?

firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
  • What is your entrypoint? If user specifies `docker run --entrypoint='sh --noprofile --norc'` there is nothing you can do, no file will/should be sourced. My guess would be to add the `source` command to `/etc/profile` or other. What docker image are you using? What is you command? What is your entrypoint? The `.bashrc` file is sourced only if the shell is interactive. – KamilCuk Aug 05 '19 at 13:36
  • That question lists out almost every alternative there is, up to setting them up in an entrypoint script that runs when the container launches. (Shell dotfiles are one of those things that mostly don’t work in Docker.) – David Maze Aug 05 '19 at 14:05
  • You have several typos in your attempt. The Bash startup file's name is spelled ` .bashrc` and you can't have spaces around the equals sign in variable assignments; see https://stackoverflow.com/questions/26971987/assignment-of-variables-with-space-after-the-sign – tripleee Aug 05 '19 at 14:54

1 Answers1

0

Have you thought using a docker-compose.yml file to make a stack of containers? It can also just include a single container but you are able to add environment variables there using the environment: tree.

Then, instead of running docker run, you will need to install docker-compse and then can start your stack (meaning all of your containers inside the docker-compose.yml file.

However, it is still essential how your entry point works. If it is a binary file, it will run in that environment where the variable will be present. If it was another shell script, that entry script will need to export that variable in order to make it available to the next sub process.

What you can also do is to change the ENTRYPOINT of the dockerfile and add your VAR=KEY variable definitions in front of it. They will be available to the sub process:

ENTRYPOINT variable1=value1 variable2=value2 myprocess.sh

If you are not in control of the container, you can build your own image from the original image and just change the entry point:

FROM other/image:latest
ENTRYPOINT variable1=value1 variable2=value2 myprocess.sh

Obviously what you want to lookup from the original image is how its ENTRYPOINT looks like so that you can modify it just the way you need.