添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
WARNING: The VAR1 variable is not set. Defaulting to a blank string.
WARNING: The VAR2 variable is not set. Defaulting to a blank string.
Recreating project_test-environment_1 ... done
Attaching to project_test-environment_1
test-environment_1  | variable1 = ; variable2 =
project_test-environment_1 exited with code 0

It seems like environment variables were not initialized. Using alternative syntax

environment:
 - VAR1='variable 1'
 - VAR2=222

given the same result too.

docker info output:

Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 5
Server Version: 18.09.2
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries 
 splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
 seccomp
 Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 973.8MiB
Name: linuxkit-00155d694b07
ID: NA32:YPM3:D5GL:JQBM:H4BN:LE2B:4HLN:5B4A:AI7T:6SDS:LSVZ:P74L
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 47
 System Time: 2019-05-14T08:44:02.5767035Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

Does anyone has any ideas to solve problem?

P.S. Sorry for my English.

This line command: echo variable1 = $VAR1; variable2 = $VAR2 tells you will specify the those value form outside. Try this VAR1="HELLO" VAR2="THERE" docker-compose up -d – Akshay barahate May 14, 2019 at 8:59
  • variable-substitution
  • docker inspect command to check if env variables are configured properly for that container.
  • I used version 3 as my docker-compose do not support the version you are using.
  • The .env file feature only works when you use the docker-compose up command and does not work with docker stack deploy.
  • You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign. This also prevents Compose from interpolating a value, so a $$ allows you to refer to environment variables that you don’t want processed by Compose.
  • If you forget and use a single dollar sign ($), Compose interprets the value as an environment variable and warns you:
  • WARNING: The VAR1 variable is not set. Defaulting to a blank string. WARNING: The VAR2 variable is not set. Defaulting to a blank string.

    the environment option specifies which vars will be passed to the container. they are not available outside in the docker-compose file. if you need env vars for your docker-compose file, create on the same directory a .env file:

    #.env
    VAR1=variable1
    VAR2=222
    

    and now it should work for docker-compose up

    remove the environment option from the docker-compose - unless you need the vars inside the container, it makes no sense.

    Just checked your approach. It worked. Same problem 2 solutions Great. Upvoting the answer – Akshay barahate May 14, 2019 at 9:48

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.