Defining environment variables

Docker provides a lot of ways to specify the environment variables of a container. In the docker-compose.yml file specified earlier; we use the env_file approach. Furthermore, we can proceed by creating the api/api.env file in the corresponding path specified in the definition of the catalog_api container:

ASPNETCORE_URLS=http://*:5000;https://*:5001
ASPNETCORE_ENVIRONMENT=Integration

The file syntax expects each line in the file to be in the following format: VAR=VAL. In the preceding case, we are defining the environment variables used by ASP.NET Core to run the service: the ASPNETCORE_URLS variable specifies the URLs used by the web service and ASPNETCORE_ENVIRONMENT specifies the environment name used by the application. In the same way, we should also proceed by defining the db/db.env file in the corresponding folder:

SA_PASSWORD=P@ssw0rd
ACCEPT_EULA="Y"

In this case, the file defines the corresponding variables for the SQL Server container: SA_PASSWORD specifies the system administrator account password, the ACCEPT_EULA needed by the startup process of SQL Server.

In addition to this, docker-compose supports declaring default environment variables in the .env file. The file must be placed in the same directory as the docker-compose.yml file. The file contains some simple rules for defining environment variables. Let's create a new .env file in the root folder of the catalog service directory:

COMPOSE_PROJECT_NAME=store

The COMPOSE_PROJECT_NAME variable is a reserved variable of the docker-compose command provided by Docker. It specifies the project name to use to run the containers. Therefore, both the catalog_api and catalog_db containers will run under the same project, called store.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.134