The rationale for this is that Dockerfiles should be fully portable and not tied to any specific environment.
It's a good idea to follow Docker best practice and avoid depending on Configuration variables in instructions in your Dockerfile, but if you absolutely need to, Aptible provides a workaround:
When building your image, Aptible injects a
.aptible.env file at the root of your repository prior to running the Docker build. The file contains your Configuration variables, and can be sourced by a shell.
Here's an example:
RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]:123/db
If needed, you can use this file to access environment variables during your build, like this:
# Assume that you've already ADDed your repo: ADD . /app WORKDIR /app # The bundle exec rake assets:precompile command # will run with your configuration RUN set -a && . /app/.aptible.env && \ bundle exec rake assets:precompile
Do not use the
.aptible.envfile outside of Dockerfile instructions.
This file is only injected when your image is built, so changes to your configuration will not be reflected in the
.aptible.envfile unless you deploy again or rebuild.
Outside of your Dockerfile, your configuration variables are accessible in the Container Environment.
Updated 11 months ago