Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Docker fig.yml reference


May 22, 2021 Docker From entry to practice



Each service fig.yml needs to specify a mirror or mirror build. Like the command line of docker run other content is optional.

docker run by docker run Dockerfile (e.g. CMD EXPOSE VOLUME ENV are the default settings already provided - you do not need to fig.yml

image

It can be set up as part of a label or mirror ID. It can be local or remote - if the mirror does not exist locally, Fig will try to pull the image away.

image: ubuntu
image: orchardup/postgresql
image: a4bc65fd

build

Specify Dockerfile is located. Fig will build the image and generate a name for it, and then use the image.

build: /path/to/build/dir

command

Overrides the default command.

command: bundle exec thin -p 3000

links

Connect containers in other services. You can use a service name (often also used as an alias) or a service name (SERVICE:ALIAS)

links:
 - db
 - db:database
 - redis

You can create an /etc/hosts in the container of the service. For example:

172.17.2.186  db
172.17.2.186  database
172.17.2.187  redis

Environment variables will also be created - a detailed view of the environment variable reference section.

ports

Exposed port. You can use the host (HOST:CONTAINER) or simply the port of the container (the host will randomly select the port).

Note: When you use HOST:CONTAINER to map ports, if you use a container port less than 60, you may get incorrect YAML xx:yy to 60. So we recommend specifying your port map with characters.

ports:
 - "3000"
 - "8000:8000"
 - "49100:22"
 - "127.0.0.1:8001:8001"

expose

Exposed ports that are not published to host hosts - they are accessed only by connected services. Only internal ports can be specified.

expose:
 - "3000"
 - "8000"

volumes

Volume mount path settings. You can set the host (HOST:CONTAINER) or access (HOST:CONTAINER:ro)

volumes:
 - /var/lib/mysql
 - cache/:/tmp/cache
 - ~/configs:/etc/configs/:ro

volumes_from

Mount all volumes from another service or container.

volumes_from:
 - service_name
 - container_name

environment

Set the environment variable. You can use arrays or dictionaries in both formats.

The environment variable is parsed to a key on the machine running Fig It helps with security and specified host values.

environment:
  RACK_ENV: development
  SESSION_SECRET:

environment:
  - RACK_ENV=development
  - SESSION_SECRET

net

Set network mode. Use the same value as the --net of docker client

net: "bridge"
net: "none"
net: "container:[name or id]"
net: "host"

dns

Configure the DNS server. It can be a value or a list.

dns: 8.8.8.8
dns:
  - 8.8.8.8
  - 9.9.9.9

working_dir, entrypoint, user, hostname, domainname, mem_limit, privileged

These are docker run correspond to docker run.

working_dir: /code
entrypoint: /code/entrypoint.sh
user: postgresql

hostname: foo
domainname: foo.com

mem_limit: 1000000000
privileged: true