官术网_书友最值得收藏!

Setting environment variables with ENV

ENV, unlike some of these other commands, should be mostly self-explanatory: it sets the environmental variables both in the Dockerfile and the container. Since we would need to keep re-typing /srv/www/html in our Dockerfile, in order to prevent typos and to ensure easy changes to our final server directory target, we set the SRV_PATH variable that we keep reusing with $SRV_PATH later. Generally for Docker containers, almost all the configurations to containers are done through environmental variables such as these, so expect to see this directive more in the later chapters.

Even though we don't use it in this example, you need to watch out when using environment variables in the CMD directive directly as it does not get expanded but runs directly. You can ensure that your variable gets expanded in CMD by using it as part of a shell command structure similar to this: CMD [ "sh", "-c", "echo", "$SRV_PATH" ].

主站蜘蛛池模板: 黄冈市| 晋城| 谢通门县| 江门市| 星子县| 北碚区| 海盐县| 榆中县| 舞阳县| 保山市| 伊川县| 横山县| 枞阳县| 河池市| 循化| 景泰县| 云霄县| 陇川县| 乌海市| 孟州市| 嘉义市| 固安县| 杭锦后旗| 南城县| 萝北县| 嘉祥县| 阜宁县| 望奎县| 嘉善县| 珲春市| 建昌县| 孟村| 裕民县| 黑水县| 东至县| 宁明县| 金乡县| 盘山县| 囊谦县| 咸宁市| 吴桥县|