Skip to content

Configuration not loaded when built with Docker #1773

@lazynoda

Description

@lazynoda

I'm trying to load the configuration (as explained in the docs) and it works well when running the service locally, but it fails when the service is built & executed via Docker image. Here is a basic encore project with the minimal stuff to test this issue: config-issue.zip

The service contains the following endpoint and config load
package config

import (
	"context"
	"encore.dev/config"
)

type Response struct {
	Data string `json:"data"`
}

type Configuration struct {
	PropertyName config.String
}

var cfg = config.Load[*Configuration]()

//encore:api public method=GET path=/config
func Invoke(ctx context.Context) (*Response, error) {
	return &Response{
		Data: cfg.PropertyName(),
	}, nil
}
And this is the configuration file
PropertyName: "Property value"

The service is built and executed via

encore build docker config-issue
docker run \
    -p 9999:8080 \
    -d \
    --name encore \
    config-issue:latest

Doing the request to http://localhost:9999/config results in panic because cfg is nil.


After further investigation, apparently the Docker image does not contain the environment variables ENCORE_CFG_{SERVICE_NAME} (took a bit to discover this). If I add that environment variable to the Docker container, then everything works again:

docker run \
    -p 9999:8080 \
    -e ENCORE_CFG_CONFIG='eyJQcm9wZXJ0eU5hbWUiOiJSYW5kb20gdmFsdWUifQ' \
    -d \
    --name encore \
    config-issue:latest
For anyone interested, the environment variable value is the configuration, JSON marshalled and then Base64 encoded.

cfgBytes, err := base64.RawURLEncoding.DecodeString(envVar)

return __unmarshaler(itr, nil)


I don't know if the problem is that encore build docker doesn't export that environment variables into the Docker image, or there is a lack in the documentation specifying how to set / override configs in Docker. Depending on the expected behaviour. If you ask me, I'd export the environment variables because the config can be configured depending on the meta Environment.Cloud and it can be docker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions