0

For example, if inside docker container I create a variable as -

/#  token="dsfgkd-sdasdas-fas3ad-ssssad"

exit

root@testvm:~# echo $token

//how to get the result..?

root@testvm:~#
toonice
  • 2,211
  • 1
  • 13
  • 20
Ashwinse
  • 1
  • 1
  • If you exit the session, the variable will no longer exist. I think you might want to be using environment variables instead. You can then access them from the host as mentioned [here](http://stackoverflow.com/questions/34051747/get-environment-variable-from-docker-container). – chvndb Apr 28 '17 at 08:20

1 Answers1

2

Containers are isolated from the host, but the host can connect inside the container

If you create your variable and export it, it will be available for your container and the connections coming from a

docker exec -it container_name_or_id bash

or

docker exec -it container_name_or_id echo $token

you can see the environment variables in your container with

docker exec -it container_name_or_id env

if you just create it in your process, it will be available for your process only

The ENV directive in a Dockerfile is designed for creating ernvironment variables at build time

see the doc

https://docs.docker.com/engine/reference/builder/#env

At run time, you have

docker run -e

extract from

https://docs.docker.com/v1.11/engine/reference/run/

docker run -e "deep=purple" --rm ubuntu /bin/bash -c export

and

docker run --env-file

see from

https://docs.docker.com/engine/reference/commandline/run/

--env-file Read in a file of environment variables

user2915097
  • 30,758
  • 6
  • 57
  • 59