Add blank lines around headers

This commit is contained in:
yeasy
2026-03-24 09:27:04 -07:00
parent 857e3b73f6
commit ae8636e96f
112 changed files with 468 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ ENV <key1>=<value1> <key2>=<value2> ...
ENV NODE_VERSION 20.10.0
ENV APP_ENV production
```
#### 设置多个变量
```docker
@@ -53,6 +54,7 @@ WORKDIR $APP_HOME
COPY . $APP_HOME
```
#### 2. 容器运行时使用
```docker
@@ -106,6 +108,7 @@ $ docker run -e APP_ENV=development -e DEBUG=true myimage
$ docker run --env-file .env myimage
```
#### .env 文件格式
```bash
@@ -165,6 +168,7 @@ RUN apt-get install nginx=${NGINX_VERSION}
RUN apt-get install nginx=1.25.0
```
#### 2. 不要存储敏感信息
```docker
@@ -178,6 +182,7 @@ ENV DB_PASSWORD=secret123
...
```
#### 3. 为应用提供合理默认值
```docker
@@ -185,6 +190,7 @@ ENV APP_ENV=production \
APP_PORT=8080 \
LOG_LEVEL=info
```
#### 4. 使用有意义的变量名
```docker
@@ -215,12 +221,14 @@ CMD ["python", "app.py", "--port", "$PORT"]
CMD ["sh", "-c", "python app.py --port $PORT"]
```
#### Q如何查看容器的环境变量
```bash
$ docker inspect mycontainer --format '{{json .Config.Env}}'
$ docker exec mycontainer env
```
#### Q多行 ENV 还是多个 ENV
```docker