YAML template file Syntax

Source: Internet
Author: User
Tags docker run

YAML template file Syntax

The default template file is Docker-compose.yml, where each service defined must be automatically built with the image directive specifying the mirror or build instruction (requires Dockerfile).
Most of the other instructions are similar to those in Docker run.
If you use the build directive, the options set in Dockerfile (for example: CMD, EXPOSE, VOLUME, ENV, etc.) will be automatically acquired without having to be set again in Docker-compose.yml.
Image
Specifies the mirror name or mirror ID. If the image does not exist locally, Compose will attempt to pull the image.
For example:

image: ubuntuimage: orchardup/postgresqlimage: a4bc65fd
Build

Specifies the path to the folder where Dockerfile is located. The Compose will use it to automatically build this image and then use this image.
Build:/path/to/build/dir

Command

Overrides the command that is executed by default after the container starts.
Command:bundle EXEC thin-p 3000

Links

Links to containers in other services. Use the service name (both as an alias) or service name: the service alias (Service:alias) format is available.
Links
-DB
-Db:database
-Redis
The aliases used will be automatically created in the/etc/hosts in the service container. For example:
172.17.2.186 DB
The corresponding environment variables will also be created.

External_links

Links to containers outside of docker-compose.yml, not even compose managed containers. The parameter format is similar to links.
External_links:
-Redis_1
-Project_db_1:mysql
-Project_db_1:postgresql

Ports

Exposes port information.
You can use the Host: container (host:container) format or simply specify the port of the container (the host will randomly select the port).

Ports

-"3000"
-"8,000:8,000"
-"127.0.0.1:8001:8001"
Note: When using the Host:container format to map ports, if you are using a container port less than 60 you may get the wrong result because YAML will parse xx:yy in this number format as 60 binary. Therefore, it is recommended to use string format.

Expose

Exposes the port, but does not map to the host, and is accessed only by the connected service.
Only internal ports can be specified as parameters
Expose
-"3000"
-"8000"

Volumes

The volume mount path setting. You can set the host path (Host:container) or add access mode (HOST:CONTAINER:RO).
Volumes
-/var/lib/mysql
-Cache/:/tmp/cache
-~/configs:/etc/configs/:ro

Volumes_from

Mount all of its volumes from another service or container.
Volumes_from:
-Service_Name
-Container_name

Environment

Set environment variables. You can use either an array or a dictionary format.
A variable of the given name automatically gets its value on the Compose host, which can be used to prevent the disclosure of unnecessary data.
Environment:
-Rack_env=development
-Session_secret

Env_file

Gets the environment variable from the file, which can be a separate file path or list.
If a template file is specified by docker-compose-f files, the path in Env_file is based on the template file path.
If there is a conflict between the variable name and the environment directive, the latter will prevail.
Env_file:. env
Env_file:
-./common.env
-./apps/web.env
-/opt/secrets.env
Each row in the environment variable file must conform to the format, and the comment lines that begin with # are supported.
# Common.env:Set Rails/rack Environment
Rack_env=development

Extends

Scale based on existing services. For example, we already have a webapp service, and the template file is common.yml.
# COMMON.YML
WebApp
Build:./webapp
Environment:
\-Debug=false
\-Send_emails=false
Write a new development.yml file that is extended using the WebApp service in COMMON.YML.

Development.yml

Web:
Extends
File:common.yml
Service:webapp
Ports
\-"8,000:8,000"
Links
\-DB
Environment:
-Debug=true
Db:
Image:postgres
The latter will automatically inherit the WebApp service and related variables in common.yml.

Net

Set the network mode. Use the same values as the--net parameter of the Docker client.
NET: "Bridge"
NET: "None"
NET: "Container:[name or ID"
NET: "Host"

Pid

Share the process namespace with the host system. Containers that open this option can access and manipulate each other through the process ID.
PID: "Host"

Dns

Configure the DNS server. Can be a value, or it can be a list.
dns:8.8.8.8
Dns:
-8.8.8.8
-9.9.9.9

Cap_add, Cap_drop

Add or discard the container's Linux capabilities (capabiliity).
Cap_add:
-All
Cap_drop:
-Net_admin
-Sys_admin

Dns_search

Configure the DNS search domain. Can be a value, or it can be a list.
Dns_search:example.com
Dns_search:
-Domain1.example.com
\-Domain2.example.com
Working_dir, entrypoint, user, hostname, domainname, mem_limit, privileged, restart, Stdin_open, TTY, Cpu_shares
These are similar to the options supported by Docker run.
cpu_shares:73
Working_dir:/code
EntryPoint:/code/entrypoint.sh
User:postgresql
Hostname:foo
Domainname:foo.com
mem_limit:1000000000
Privileged:true
Restart:always
Stdin_open:true
Tty:true

YAML template file Syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.