logo
Tags down

shadow

docker-compose set environment variable doesn't work


By : Krystal
Date : October 17 2020, 08:10 AM
will help you I use docker and also use docker-compose for tie each container. , [SOLVED]
It is caused by supervisor.
code :


Share : facebook icon twitter icon

docker-compose, can't print environment variable in docker container


By : user1378341
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Compose will expand variables from the environment where you are running compose. To expand the variable inside your container, escape the $ using $$:
code :
command: '/bin/sh -c "echo $$DEBUG"'

Passing environment variable to docker image at build time with docker-compose


By : user1459385
Date : March 29 2020, 07:55 AM
around this issue Your example is working for me.
Have you tried deleting the images and building again? Docker won't re-build your image despite environment variables changed if the image is in cache.
code :
 docker-compose down --rmi all
$ cat Dockerfile
FROM alpine
ARG BUILD_VERSION
ENV BUILD_VERSION=$BUILD_VERSION
RUN echo Build Time: $BUILD_VERSION

$ cat docker-compose.yml
version: '3'
services:
  app:
    build:
      context: .
      args:
        - BUILD_VERSION
$ export BUILD_VERSION=122221
$ docker-compose up --build
Creating network "a_default" with the default driver
Building app
Step 1/4 : FROM alpine
latest: Pulling from library/alpine
8e3ba11ec2a2: Pull complete
Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430
Status: Downloaded newer image for alpine:latest
---> 11cd0b38bc3c
Step 2/4 : ARG BUILD_VERSION
---> Running in b0a1a79967a0
Removing intermediate container b0a1a79967a0
---> 9fa331d63f6d
Step 3/4 : ENV BUILD_VERSION=$BUILD_VERSION
---> Running in a602c27689a5
Removing intermediate container a602c27689a5
---> bf2181423c93
Step 4/4 : RUN echo Build Time: $BUILD_VERSION                <<<<<< (*)
---> Running in 9d828cefcfab
Build Time: 122221
Removing intermediate container 9d828cefcfab
---> 2b3afa3d348c
Successfully built 2b3afa3d348c
Successfully tagged a_app:latest
Creating a_app_1 ... done
Attaching to a_app_1
a_app_1 exited with code 0
$ cat docker-compose
version: '3'
services:
  app1:
    build:
      context: .
      args:
        - BUILD_VERSION=$APP1_BUILD_VERSION
  app2:
    build:
      context: .
      args:
        - BUILD_VERSION=$APP2_BUILD_VERSION
$ export APP1_BUILD_VERSION=1.1.1
$ export APP2_BUILD_VERSION=2.2.2
$ docker-compose build
Building app1
Step 1/4 : FROM alpine
latest: Pulling from library/alpine
8e3ba11ec2a2: Pull complete
Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430
Status: Downloaded newer image for alpine:latest
---> 11cd0b38bc3c
Step 2/4 : ARG BUILD_VERSION
---> Running in 0b66093bc2ef
Removing intermediate container 0b66093bc2ef
---> 906130ee5da8
Step 3/4 : ENV BUILD_VERSION=$BUILD_VERSION
---> Running in 9d89b48c875d
Removing intermediate container 9d89b48c875d
---> ca2480695149
Step 4/4 : RUN echo Build Time: $BUILD_VERSION
---> Running in 52dec27874ec
Build Time: 1.1.1
Removing intermediate container 52dec27874ec
---> 1b3654924297
Successfully built 1b3654924297
Successfully tagged a_app1:latest
Building app2
Step 1/4 : FROM alpine
---> 11cd0b38bc3c
Step 2/4 : ARG BUILD_VERSION
---> Using cache
---> 906130ee5da8
Step 3/4 : ENV BUILD_VERSION=$BUILD_VERSION
---> Running in d29442339459
Removing intermediate container d29442339459
---> 8b26def5ef3a
Step 4/4 : RUN echo Build Time: $BUILD_VERSION
---> Running in 4b3de2d223e5
Build Time: 2.2.2
Removing intermediate container 4b3de2d223e5
---> 89033b10b61e
Successfully built 89033b10b61e
Successfully tagged a_app2:latest

Docker-compose doesnt set environment variable


By : Alirith04
Date : March 29 2020, 07:55 AM

Docker compose work on linux environment but not windows environment


By : user2964842
Date : March 29 2020, 07:55 AM
This might help you I think you want to fix the sh script in your Dockerfile
add this:
code :
RUN  apt-get update && apt-get install -y dos2unix && dos2unix /path/to/the/script

How to set environment variable into docker container using docker-compose


By : jeski
Date : March 29 2020, 07:55 AM
Does that help While creating this question I have been resolve this problem in a funny and easy way but I have been thought that I post answer to help someone in the future with similiar problem.
All you have to do is remove " " (space) next = sign so two last lines of docker-compose.yml should looks like this: environment: - GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/CryptoTraderBot-901d31d199ce.json
shadow
Privacy Policy - Terms - Contact Us © voile276.org