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

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" ].

主站蜘蛛池模板: 黄山市| 九龙坡区| 安乡县| 基隆市| 洪湖市| 惠东县| 军事| 阿勒泰市| 丰宁| 曲阜市| 慈溪市| 高淳县| 永顺县| 遵化市| 开远市| 西乌珠穆沁旗| 朝阳市| 遂宁市| 朝阳市| 亳州市| 德令哈市| 鹤峰县| 略阳县| 眉山市| 钦州市| 定结县| 高平市| 高碑店市| 长沙县| 长岭县| 滦南县| 当雄县| 博湖县| 全州县| 浏阳市| 虹口区| 北辰区| 礼泉县| 武汉市| 桃江县| 太湖县|