> For the complete documentation index, see [llms.txt](https://camelgemonion.gitbook.io/docker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://camelgemonion.gitbook.io/docker/dockercompose.yaml-wen-jian-zhong-chang-yong-zhi-ling/untitled-12/untitled-7/chang-yu-fa-xing-shi.md).

# 长语法形式

对于如何定义config，长语法提供了更加细粒度的方式。

* source：Docker中已经存在的config的名称
* target：被挂载到服务的任务容器上的路径和文件名。如果没有指定，默认是/\<source>
* uid和gid：在服务的任务容器中，uid和gid代表的用户和用户组拥有被挂载的config文件。如果没有指定，默认两个值都为0。不支持windows系统。
* mode：被挂载到服务的任务容器中的文件权限，以八进制命名。例如0444代表只读。默认是0444权限。配置（Configs）无法被写入，因为它们被挂载在临时的文件系统中。因此，如果你设置写的权限位，该权限位会被忽视。可以设置可执行的权限位。如果不熟悉Unix文件权限模式，参考[权限计算](http://permissions-calculator.org/)。

下面示例中，my\_config被设置为redis\_config, 权限设置为0440，uid和gid设置为103。redis服务没有权限访问my\_other\_config配置。

```
 version: "3.8"
 services:
   redis:
     image: redis:latest
     deploy:
       replicas: 1
     configs:
       - source: my_config
         target: /redis_config
         uid: '103'
         gid: '103'
         mode: 0440
 configs:
   my_config:
     file: ./my_config.txt
   my_other_config:
     external: true
```

可以同时授权访问多个服务，也可以长语法和短语法形式混用。定义了配置以后，不会隐示授权一个服务去使用它。
