|
Size: 1622
Comment:
|
Size: 2304
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 19: | Line 19: |
| == Configuration == ---- |
|
| Line 31: | Line 25: |
| Docker supports two methods for binding volumes, hereafter referred to as the 'long syntax' and the 'short syntax'. Docker Compose supports two parallel methods. Upstream recommendation is to use the long syntax. The long syntax is as follows: |
Docker compose supports two methods for creating [[Docker/Volumes|volumes]] and [[Docker/BindMounts|bind mounts]]. The '''long''' syntax, which is recommended, is: |
| Line 36: | Line 28: |
| container_name: CONTAINER | container_name: my-container |
| Line 40: | Line 32: |
| image: IMAGE | image: my-image |
| Line 48: | Line 40: |
| The short syntax is as follows: | The '''short''' syntax is: |
| Line 51: | Line 43: |
| container_name: CONTAINER | container_name: my-container |
| Line 55: | Line 47: |
| image: IMAGE | image: my-image |
| Line 62: | Line 54: |
| === Port Management === | === Publishing === |
| Line 64: | Line 56: |
| To give a container access to ports, use: | Docker compose supports two methods to expose a container to the network. The '''short''' syntax is: |
| Line 67: | Line 59: |
| container_name: CONTAINER | container_name: my-container |
| Line 71: | Line 63: |
| image: IMAGE | image: my-image |
| Line 73: | Line 65: |
| - 8888:8888 | - 127.0.0.1:80:8080/tcp |
| Line 75: | Line 67: |
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"`). |
|
| Line 83: | Line 105: |
| container_name: CONTAINER | container_name: my-container |
| Line 87: | Line 109: |
| image: IMAGE | image: my-image |
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 com,pose reference documentation
