# Dockerfile和docker-compose.yml设置时区

> Dockerfile和docker-compose.yml设置时区

### 一、Dockerfile设置时区

```bash
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai'>/etc/timezone
使用RUN命令设置时区。
```

### 二、docker-compose.yaml中配置时区

**方式1：**

```bash
environment:
  - SET_CONTAINER_TIMEZONE=true
  - CONTAINER_TIMEZONE=Asia/Shanghai

#或者这样写

environment:
  SET_CONTAINER_TIMEZONE: true
  CONTAINER_TIMEZONE: Asia/Shanghai
```

**方式2：**

```bash
environment:
  - TZ=Asia/Shanghai

#或者这样写

environment:
  TZ: Asia/Shanghai 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/centos/docker/dockerfile-he-dockercompose.yml-she-zhi-shi-qu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
