As my chaincode will get execute on each chaincode container, I want to set environment variable inside every chaincode container so that i can use this environment variable in my chaincode.
I don't have access to create a chaincode container. It will get created automatically at the time of chaincode instantiation (one docker container per peer). So that i don't have any control to set the environment variable inside chaincode containers.
I also think to update and commit the chaincode containers, but if there are more endorsing peers then this could take unnecessary delay. So according to my understanding, the best way is to set the environment variable at the time of container creation.
Please let me know how to solve above problem?
You do not want to set an environment variable. If there is some type of "configuration" setting you need to pass into chaincode then you should pass it as a parameter to the Init function and then save the value using PutState and retrieve it using GetState as required.
If you want to set environment variables before running a container, use the --env
argument for the docker run
command:
$ docker run --help ... -e, --env list Set environment variables --env-file list Read in a file of environment variables
Use the -e
, --env
, and --env-file
flags to set simple (non-array) environment variables in the container you're running, or overwrite variables that are defined in the Dockerfile of the image you're running. More info is here .
docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
If you want to set environment variables after running a container, Docker does not allow this currently. See these issues:
https://github.com/moby/moby/issues/8838
https://github.com/moby/moby/issues/7561
Right now Docker can't change the configuration of the container once it's created, and generally this is OK because it's trivial to create a new container
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.