Pass environment variables to docker container

Environment variables can be passed with the -e option when running docker run. Used to pass configuration information.

$ docker run --help | grep -e "-e"
  -e, --env list                       Set environment variables

Verification

$ docker run -it --rm -e HOGE=FUGA -e AAA=BBB centos:centos8 /bin/bash 
[root@45aa4a408e51 /]# echo $HOGE
FUGA
[root@45aa4a408e51 /]# echo $AAA
BBB
[root@45aa4a408e51 /]# 

You can also pass environment variables from a file in which environment variables are written by using --env-file.

.env_test


HOGE=FUGA
A=B
TEST=TESTdesu
$ docker run --env-file ./.env_test --rm -it centos:centos8 /bin/bash
[root@d9801c8c2542 /]# echo $HOGE
FUGA
[root@d9801c8c2542 /]# echo $A
B
[root@d9801c8c2542 /]# echo $TEST
TESTdesu

Recommended Posts

Pass environment variables to docker container
Introduce dotenv to Docker + Rails to manage environment variables
How to apply Rails environment variables to Docker container (aws :: Sigv4 :: Errors solution)
Introduction to Linux Container / Docker (Part 1)
Introduction to Linux Container / Docker (Part 2)
[Docker] Operation up to container creation # 2
Docker push to GitHub Container Registry (ghcr.io)
[Docker] Use environment variables in Nginx conf
[Docker] Building an environment to use Hugo
Migrate existing Rails 6 apps to Docker environment
Docker container build fails to install php-radis
How to use environment variables in RubyOnRails
[Spring MVC] How to pass path variables
How to build Rails 6 environment with Docker
Small Docker container
[Node.js express Docker] How to define Docker environment variables and load them with node.js
Docker environment construction
How to check the logs in the Docker container
How to get a heapdump from a Docker container
(Basic authentication) environment variables in rails and Docker
Setting to exit from Docker container with VScode
Copy files from docker container to host (docker cp)
I made a Docker container to run Maven
How to update pre-built files in docker container
[Rails] How to build an environment with Docker
Temporarily move Docker environment from Mac to AWS
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
Steps to push Docker image to GitHub Container Registry (ghcr.io)
How to build docker environment with Gradle for intelliJ
Rails Docker environment construction
[Docker environment] How to deal with ActiveSupport :: MessageEncryptor :: InvalidMessage
Create a Docker container to convert EPS to PGF source
How to install Docker
Command memo to install xeyes in ubuntu docker environment
Docker container usage scene
Try to build a Java development environment using Docker
Push Docker images from GitHub Actions to GitHub Container Registry
I tried to build an environment using Docker (beginner)
How to set environment variables when using Payjp with Rails
Wait for the container service to start with docker healthcheck
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Express ~
How to set and describe environment variables using Rails zsh
I tried to create React.js × TypeScript × Material-UI on docker environment
I tried to build the environment little by little using docker
How to build Rails, Postgres, ElasticSearch development environment with Docker
Build a Node-RED environment with Docker to move and understand
I tried to build the environment of WSL2 + Docker + VSCode
[Rails 5] How to use gem gon ~ How to pass variables from Rails to JS ~
I tried to create a padrino development environment with Docker
[Docker context] ~ How to access docker in remote environment from VScode ~
Introduction to batch files (for statements, arrays, deferred environment variables)
[Docker] How to access the host from inside the container. http://host.docker.internal:
Connect to AWS RDS from your local PC Docker environment
Pytorch execution environment with Docker
WSL2 + VSCode + Docker development environment
[Docker] Create Elasticsearch, Kibana environment!
Migrating from vargrant to docker
MySQL 5.7 (Docker) environment construction memo
[Environment variables] What are rails environment variables?
How to set Docker nginx
Redmine (Docker) environment construction memo