hello.

with 3 layers as you have notice the shell expansion and the evaluation of
the command is happening before the layer you want to do..

is a bit hard to control 3 layers, you will have to use \ to make some
characters literal and hope will get evaluated inside the proper layer.

plus if those variables like DB_PORT_5432_TCP_ADDR exists on a file that
get initiated in the shell login, not all the logins are the same, so
.bash_profile is not read always

My suggestion will be

create a file that have those variables set

say

pgsql.env

inside

DB_PORT_5432_TCP_ADDR=awesomehostname

then in .bash_profile you can use

. ~/pgsql

and that will use the variables

and on your command you could do

. pgsql ; command $DB_PORT_5432_TCP_ADDR



Example:

mini:~ alvarom$ cat pgsql.env
DB_PORT_5432_TCP_ADDR="awesomeserver"
mini:~ alvarom$ ssh localhost '. pgsql.env ; echo
$DB_PORT_5432_TCP_ADDR'
awesomeserver
mini:~ alvarom$









On Thu, Jul 17, 2014 at 5:16 AM, Isaac Cambron <[email protected]> wrote:

> I have what I'm sure is a dumb problem, and likely betrays some
> misunderstanding about Vagrant, Docker, shells, or possibly all three. But
> here goes: I'm running Vagrant with a Docker provider, using the default
> boot2docker host VM. What I'm trying to do is run some commands, but the
> problem is that my shell variables are being interpreted in the host VM's
> environment instead of the container's. To demonstrate:
>
> -> vagrant docker-run db -- whoami
> ==> db: Docker host is required. One will be created if necessary...
> --SNIP--
>      db: root
>
> That's correct; my Postgres container runs as root. But:
>
> -> vagrant docker-run db -- sh -c 'echo $(whoami)'
> ==> db: Docker host is required. One will be created if necessary...
> --SNIP--
>     db: docker
>
> Which is silly. It looks like the $(whoami) is being evaluated by the host
> VM, where the user is named docker. That example is contrived, but the
> underlying problem keeps me from accessing environment variables that do
> matter:
>
> -> vagrant docker-run db -- sh -c 'exec psql -h "$DB_PORT_5432_TCP_ADDR"
> -p "$DB_PORT_5432_TCP_PORT" -U postgres'
>
> Which doesn't work because (as I understand it) those vars are getting
> evaluated to nothing in the host, which of course has no idea what port I
> have PG set up on.
>
> Any ideas on how to fix this? Perhaps there's some extra level of
> indirection I need to put into the command itself, or maybe I'm just
> missing something.
>
> Thanks,
> Isaac
>
> --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to