|
Size: 634
Comment:
|
← Revision 11 as of 2023-04-04 18:09:26 ⇥
Size: 2301
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 2: | Line 2: |
'''Docker Compose''' is a method for creating containers through configuration files. |
|
| Line 9: | Line 11: |
| == Environment Variables == | == Installation == |
| Line 11: | Line 13: |
| Environment variables are typically passed into Docker as a way to securely provide authentication, i.e. [[MariaDBConfiguration|the root password for MariaDB]]. It would be antithetical to security to have the variables set within the Docker Compose file. Instead, instruct Docker Compose to ''pass in'' a variable that is set already in the local user's environment. | Most [[Linux]] distributions offer a `docker-compose` package. ---- == Compose Files == === Volumes === Docker compose supports two methods for creating [[Docker/Volumes|volumes]] and [[Docker/BindMounts|bind mounts]]. The ''long'' syntax, which is recommended, is: |
| Line 14: | Line 28: |
| container name: CONTAINER | container_name: my-container |
| Line 18: | Line 32: |
| image: IMAGE | image: my-image volumes: - type: bind source: relative/source/path target: /absolute/target/path read only: true }}} The ''short'' syntax is: {{{ container_name: my-container version: 0.1 services: web: image: my-image volumes: - relative/source/path:/absolute/target/path:ro }}} === Publishing === Docker compose supports two methods to expose a container to the network. The ''short'' syntax is: {{{ container_name: my-container version: 0.1 services: web: image: my-image ports: - 127.0.0.1:80:8080/tcp }}} If the host [[Protocols/IP|IP]] is not set, the service will listen on all interfaces. If the protocol is not specified, both [[Protocols/TCP|TCP]] and [[Protocols/UDP|UDP]] connections are accepted. So it can be expressed simply as: {{{ container_name: my-container version: 0.1 services: web: image: my-image ports: - 80:8080 }}} The ''long'' syntax is: {{{ container_name: my-container version: 0.1 services: web: image: my-image ports: - target: 80 host_ip: 127.0.0.1 published: "8080" protocol: tcp mode: host }}} In this syntax, `published` is a string because it can be expressed as a range (like `"8000-9000"`). === Environment Variables === To pass in an environment variable from the local environment to a Docker container, use: {{{ container_name: my-container version: 0.1 services: web: image: my-image |
| Line 24: | Line 115: |
| ---- == See also == [[https://docs.docker.com/compose/compose-file/|Docker compose reference documentation]] |
Docker Compose
Docker Compose is a method for creating containers through configuration files.
Contents
Installation
Most Linux distributions offer a docker-compose package.
Compose Files
Volumes
Docker compose supports two methods for creating volumes and bind mounts. The long syntax, which is recommended, is:
container_name: my-container
version: 0.1
services:
web:
image: my-image
volumes:
- type: bind
source: relative/source/path
target: /absolute/target/path
read only: trueThe short syntax is:
container_name: my-container
version: 0.1
services:
web:
image: my-image
volumes:
- relative/source/path:/absolute/target/path:ro
Publishing
Docker compose supports two methods to expose a container to the network. The short syntax is:
container_name: my-container
version: 0.1
services:
web:
image: my-image
ports:
- 127.0.0.1:80:8080/tcpIf the host IP is not set, the service will listen on all interfaces. If the protocol is not specified, both TCP and UDP connections are accepted. So it can be expressed simply as:
container_name: my-container
version: 0.1
services:
web:
image: my-image
ports:
- 80:8080The long syntax is:
container_name: my-container
version: 0.1
services:
web:
image: my-image
ports:
- target: 80
host_ip: 127.0.0.1
published: "8080"
protocol: tcp
mode: hostIn this syntax, published is a string because it can be expressed as a range (like "8000-9000").
Environment Variables
To pass in an environment variable from the local environment to a Docker container, use:
container_name: my-container
version: 0.1
services:
web:
image: my-image
environment:
- VARIABLE1
- VARIABLE2
See also
Docker compose reference documentation
