Use the --build-arg option of docker-compose to pass environment variables to the container built with Dockerfile

flow

  1. Pass environment variables to Docker-Compose using the --build-arg option
  2. In Docker-Compose, declare the variable to be passed to --build-arg in advance.
  3. In DockerFile read from Docker-Compose, call the variable with ARG and embed it in the container with ENV.

Execution command

docker-compose build --build-arg BUILDID=4d345663-5247-465d-b522-1d3c08b5d243

docker-compose --Specify with args --At this time, the value of the variable is overwritten, so it is appropriate.

docker-compose.yaml


version: '3.7'
services:
  app:
    build:                                                                                        
      context: ./app
      dockerfile: ./Dockerfile
      args:    
        - BUILDID=test

Dockerfile --Read with ARG --Embed with ENV

ARG BUILDID
ENV buildid=${BUILDID}

Recommended Posts

Use the --build-arg option of docker-compose to pass environment variables to the container built with Dockerfile
Pass environment variables to docker container
How to use git with the power of jgit in an environment without git commands
I want to pass the startup command to postgres with docker-compose.
I want to recreate the contents of assets from scratch in the environment built with capistrano
[Beginner] Procedure to log in to the virtual environment built with Vagrant
[Note] How to restart the Windows container set up with docker-compose
How to use MinIO with the same function as S3 Use docker-compose
Use Priority Queue with Kotlin (1.0.0) of AtCoder (+ Investigate the environment of the judge server)
How to use args :, environment :, env_file: and .env files with docker-compose command
How to use environment variables in RubyOnRails
Up to the point of launching a Docker container built using RedHat Quarkus
How to set environment variables in the properties file of Spring boot application
Assignment to multiple variables with the ternary operator
Change the timezone of the https-portal container to JST
Output of how to use the slice method
pass two arguments to the URI with link_to
The story of adding the latest Node.js to DockerFile
Prepare the environment of CentOS 8 with Sakura VPS
If you use SQLite with VSCode, use the extension (how to see the binary file of sqlite3)
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
[Docker] How to see the contents of Volumes. Start a container with root privileges.
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
A warning is displayed when trying to use a huge integer with the special variables $ 1, $ 2, $ 3 ...
Summary of how to use the proxy set in IE when connecting with Java
Environment construction of Rails5 + MySQL8.0 + top-level volumes with docker-compose
Communicate from the outside to the container launched by docker-compose
How to boot by environment with Spring Boot of Maven
Java: Use Stream to sort the contents of the collection
You can't (yet) pass arguments to buildkit with docker-compose
I want to be aware of the contents of variables!
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
How to manage the difference in each environment with yml without increasing the number of RAILS_ENV
I tried to develop the cache function of Application Container Cloud Service in the local environment