concept environment variable in category docker

appears as: environment variables, environment variables, n environment variable, environment variable
Bootstrapping Microservices with Docker, Kubernetes and Terraform MEAP V08

This is an excerpt from Manning's book Bootstrapping Microservices with Docker, Kubernetes and Terraform MEAP V08.

We’ll talk more about ways we can test our microservices in Chapter 8: Automated testing for microservices.

export PORT=3000

Before running the new microservice we need to set the environment variables to configure it. We will do this from the terminal. On MacOS and Linux we do it like this:

Learn Docker in a Month of Lunches

This is an excerpt from Manning's book Learn Docker in a Month of Lunches.

Except that it isn’t. The application can actually be configured to use a different URL, a different interval between requests, and even a different type of HTTP call. This app reads the configuration values it should use from the system’s environment variables.

Environment variables are just key/value pairs that the operating system provides. They work in the same way on Windows and Linux, and they’re a very simple way to store small pieces of data. Docker containers also have environment variables, but instead of coming from the computer’s operating system, they’re set up by Docker in the same way that Docker creates a hostname and IP address for the container.

The web-ping image has some default values set for environment variables. When you run a container, those environment variables are populated by Docker, and that’s what the app uses to configure the website’s URL. You can specify different values for environment variables when you create the container, and that will change the behavior of the app.

# load your machine's IP address into a variable - on Windows:
     $hostIP = $(Get-NetIPConfiguration | Where-Object {$_.IPv4DefaultGateway -ne $null }).IPv4Address.IPAddress
      
     # on Linux:
     hostIP=$(ip route get 1 | awk '{print $NF;exit}')
      
     # and on Mac:
     hostIP=$(ifconfig en0 | grep -e 'inet\s' | awk '{print $2}')
      
     # pass your IP address as an environment variable for the container:
     docker container run -e DOCKER_HOST=$hostIP -d -p 9090:9090 diamol/prometheus:2.13.1

10.3 Injecting configuration with environment variables and secrets

You can isolate applications using Docker networks and capture the differences between environments with Compose overrides, but you’ll also need to change the application configuration between environments. Most applications can read configuration settings from environment variables or files, and Compose has good support for both those approaches.

Figure 18.3 Merging config from environment variables makes it easy to change specific features.
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest