Search code examples
dockerdocker-composeapache-superset

Expose host services (Postgres, Redis) to Docker container (Apache Superset)


I'm trying to setup Apache Superset.
I want to access Postgres and Redis services running on host from a Superset instance running in Docker.

(I don't want to run dockers for db and redis as I have already installed these services in my application).

I see following in superset documentation:

Note: Users often want to connect to other databases from Superset. Currently, the easiest way to do this is to modify the docker-compose-non-dev.yml file and add your database as a service that the other services depend on (via x-superset-depends-on).

Here I'm clueless on how to configure yaml file for this. I'm pretty much new to docker. Could any one please guide me? Here is the yaml file service section from docker-compose-non-dev.yml.

  redis:
    image: redis:7
    container_name: superset_cache
    restart: unless-stopped
    volumes:
      - redis:/data

  db:
    env_file: docker/.env-non-dev
    image: postgres:14
    container_name: superset_db
    restart: unless-stopped
    volumes:
      - db_home:/var/lib/postgresql/data```



Solution

  • If I understand correctly you want to do two things:

    1. Use existing services for those components

    Just make sure they're accessible from your Superset docker container and then specify the paths to those resources in superset_config.py or superset_config_docker.py, which is presumably where you're setting other config options. E.g., to point to your Postgres service as the backend database, specify:

    SQLALCHEMY_DATABASE_URI='postgresql://username:password@path/dbname'
    

    Where path is the URL or IP address of your Postgres instance. For Redis, it's not as clear but I think you'd set that location with REDIS_HOST= in your config. And you can use a .env file to store these strings instead of putting them directly in your config file.

    1. Not run the unnecessary containers

    You should be able to just delete the container specs you have in your post and remove both of them from the x-superset-depends-on: &superset-depends-on list at the top of the docker-compose file.