Comments (13)
@jamestenglish That would be cool, but the environment variables added by links are pretty unnecessary anyway, since:
- An entry is added to
/etc/hosts
with the name of the link (in this case,db
) - The port given to
web
will always be the one exposed bydb
, (in this case, 3306).
(This is why we no longer recommend using the environment variables provided by links.)
You can therefore just write:
environment:
DATABASE_URL: mysql://user:password@db:3306/db
from compose.
Yes! We were talking about this yesterday and I would really like this to work. I haven't thought a whole lot about how it should be implemented though โย it's a little complex because the env variables aren't available until the container has been started (I think).
Maybe we could run a one off container that simply runs env
to get the environment the container is going to see, then use that to set extra custom environment variables.
from compose.
As you said the environment variables are not available until you run the container.
The thing is that environment variables injected by docker, like the one for the links, as in your exemple :
"DB_1_PORT_3306_TCP_ADDR"
will not be the same between two instances of db, even if they have the same name.
For example here the IP won't be the same, except if you change the network settings (i assume, never tried though)
I thought that you could do this:
db:
image: example/mysql
test:
links:
- db
environment:
- MYSQL_USER=root
- MYSQL_ROOT=toor
-DATABASE_URL=mysql://$MYSQL_ROOT:$MYSQL_PASSWORD$DB_1_PORT_3306_TCP_ADDR/db
But Docker is simply injecting the environment variables without expanding them ... too bad.
That could be a feature to add directly to docker though.
from compose.
@SkinyMonkey i agree this would be a great addition to docker. are you familiar with the code? any idea where to start poking?
@bfirsh until then, any thoughts on adding this here? id love to send a pull request, but not sure where in your code is the best to do this? i see a few places in container and service where it could live. if you have thought about this, let me know where to start i can give it a shot. maybe a proof of concept here can vet out some ideas for attempting to get this in docker itself.
from compose.
Hi,
Could this be extended to being able to reference environment variables from the host machine to be injected into the docker container via fig?
e.g.
environment:
- DB_PASSWORD=$DB_PASSWORD <--this being an env variable on the host machine
from compose.
@thestonefox Yep, useful feature. See #76 - still under discussion.
from compose.
Greetings - looks like the discussion might be resolved - any chance this will make it into the next release?
Thanks!
from compose.
Closed by #297.
from compose.
@aanand I don't think this was actually close by #297, the issue in question here is reassigning autoassigned env vars to another env var (like one the codebase already expects), i.e an alias. 297 seems to allow blank envs to resolve to the host env.
from compose.
@aanand I agree with @pnegahdar the original use case:
web:
build: .
ports:
- 8000:8000
links:
- db
environment:
DATABASE_URL: mysql://user:password@${DB_1_PORT_3306_TCP_ADDR}/db
db:
image: orchardup/mysql
Does not seem to be supported by #297
specifically how would one be able to set an environment variable based on other environment variables like this line: DATABASE_URL: mysql://user:password@${DB_1_PORT_3306_TCP_ADDR}/db
I think this is an important use case as apps should not have to be burdened with changing code to support esoteric environment variable names like: DB_1_PORT_3306_TCP_ADDR
from compose.
@aanand Ah thanks, I had been out of the docker world for a little bit and didn't realize they added that feature
from compose.
Thanks a lot @aanand, your approach is perfect.
from compose.
@aanand Thank you , perfect
from compose.
Related Issues (20)
- [BUG] Variable substitution in secrets file path not working
- @derNiklaas: I have stumbled upon a similar issue, but what I discovered was that I had two services setup towards a docker network, with one of the services configured with a static ipv4 assignment, while the other did not have a static IP assigned. HOT 2
- [BUG] docker inline config when changed is not being taken into account
- ### Describe the feature or problem youโd like to solve
- Support language-specific build tools
- `docker compose config` outputs an invalid format for `deploy.resources.limits.cpus`
- ~~Should fix pbek/QOwnNotes#2952~~
- [BUG] docker compose config merges environment variables into a list HOT 3
- [BUG] usage of `--env-file` regressed from v2.27.0 to v2.27.1 HOT 4
- [BUG] docker compose config ignores services with -profile HOT 2
- [BUG] services.web.ports array items[0,1] must be unique HOT 4
- [BUG] `app_protocol`and `mode` settings of long syntax in service ports section have no effect HOT 6
- Trying to pull repository docker.io/clearwater ,failed
- support env variable COMPOSE_TIMEOUT HOT 4
- [BUG] Loading COMPOSE_FILE from .env-file stopped working HOT 1
- ci pipeline failing for .net HOT 14
- wordpress-1 | exec /usr/local/bin/docker-entrypoint.sh: exec format error HOT 2
- [BUG] Merge does not work properly with required variables HOT 1
- [BUG] (v2.28.0) Fancy (ANSI) progress output not available HOT 5
- [BUG] Docker compose does not ignore extension fields under long form depends_on HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose.