I am using a package that requires a file named config.json, which contains an API key. I am working with Laravel Sail and have edited the Dockerfile to echo the json into the file during build time.
RUN echo '{ "api_key": "someKey123" }' > /home/sail/.config/config.json
I would like to store the api key in the .env file that comes with the default Laravel install. I'm defining it in the docker-compose file.
services:
laravel.test:
build:
context: ./docker/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
API_KEY: '${API_KEY}' // <------ Here is the variable.
I've tried running this command but it doesn't echo the variable value, instead it writes the string as it is to the config.
RUN echo '{ "api_key": "${API_KEY}" }' > /home/sail/.config/config.json
How can I echo the variable content to the config file? I'm neither a bash nor Docker expert, and I know there are some specifics regarding container builds and variables that i might not understand.
Thank you for your help.