Search code examples
dockerdocker-composeapache-atlas

Can't execute command to set environment variables in docker container


I have seen the following links to execute multiple commands in docker-compose file:

which tell us how to execute multiple commands in docker-compose file (also in the docker container).

In order to run sburn/apache-atlas image properly, I have to set some environment variables which exists in /opt/apache-atlas-2.1.0/conf/atlas-env.sh directory.

I have tried the following docker-compose.yml file:

version: "3.3"

services:
  atlas:
    image: sburn/apache-atlas
    container_name: atlas
    ports:
      - "21000:21000"
    volumes:
      - "./bash_script:/app"
    command: bash -c "
      source ./opt/apache-atlas-2.1.0/conf/atlas-env.sh
      && chmod 777 /app/import-hive.sh
      && /opt/apache-atlas-2.1.0/bin/atlas_start.py
      "

Unfortunately, the first command (I mean source ./opt/apache-atlas-2.1.0/conf/atlas-env.sh) doesn't work. It doesn't have any error but the environment variables such as JAVA_HOME aren't set.

How are you checking that the variables are not set?

  1. Run Docker exec -it atlas bash in the terminal.
  2. Run set in the terminal. It shows all the environment variables.
  3. Check whether the environment variables are set or not.

Solution

  • Your question involves a lot of stuff, if you can narrow it down people can help better. Here are my suggestions to debug it:

    bash -exc "
        echo home1=$JAVA_HOME
        source ./opt/apache-atlas-2.1.0/conf/atlas-env.sh
        echo home2=$JAVA_HOME
        chmod 777 /app/import-hive.sh
        echo home3=$JAVA_HOME
        /opt/apache-atlas-2.1.0/bin/atlas_start.py
    "
    

    If JAVA_HOME is never set, there's something wrong with .sh file, either you fix that file or manually set it with

    export JAVA_ENV=/aaa/bbb/ccc
    

    Or defining it in your compose yaml file.


    Also the way you're checking for env vars is wrong, running Docker exec -it atlas bash won't run in the same bash as bash -c "source ./opt/apache-a..."