Docker container specifications
There are two ways to describe a Docker container's launch configuration:
- COI specification that allows you to run only one Docker container.
- Docker Compose specification that allows you to set a more flexible configuration, such as running multiple Docker containers and the required services.
Warning
You can only use one specification at a time: COI or Docker Compose.
COI specification
In a Container Optimized Image, the Docker container is described in a specification (YAML file) based on a Kubernetes pod spec
When creating a VM from a Container Optimized Image in the management console or YC CLI, the specification file is generated automatically using the specified data. When creating an instance group from a Container Optimized Image, you set the specification manually. A sample specification file and required keys are described below.
Sample COI specification of a Docker container
The COI specification is a YAML file with the following contents:
spec:
containers:
- command:
- sleep
args:
- 100000
env:
- name: MYENV
value: myvalue
image: cr.yandex/mirror/ubuntu:16.04
name: my-container
securityContext:
privileged: false
stdin: false
tty: false
volumeMounts:
- mountPath: /home/yc-user/cache
name: cache-volume
- mountPath: /home/yc-user/data
name: data-volume
restartPolicy: Always
volumes:
- name: cache-volume
emptyDir:
medium: Memory
- name: data-volume
hostPath:
path: /data
Where:
command
: Command executed when starting the Docker container.args
: Arguments sent to the command running in the Docker container.env
: Environment variables available in the Docker container.image
: Docker image used to create and run the Docker container.name
: Docker container to run.securityContext
: Security and access control settings inside the Docker container. You can only run a privileged Docker container.privileged
: Run the Docker container in privileged mode. Processes in privileged Docker containers can access any system device and are the same as those with root permissions on a VM. The default value is false.stdin
: Buffer for the input stream while running the Docker container. The input stream will be linked to the running Docker container. The default value is false.tty
: Allocate a TTY to the Docker container. The default value is false.restartPolicy
: Docker container restart policy.volumeMounts
: List of volumes to mount inside the Docker container.mountPath
: Path in the Docker container to mount the volume at.volumes
: Description of the volumes used in the specification.emptyDir
: Empty directory in thetmpfs
temporary file system created in the VM RAM. The contents of this directory are deleted when the Docker container it is mounted to is stopped or when the VM is restarted. To usetmpfs
, make sure to specify themedium: Memory
parameter. Volume size cannot be greater than the amount of RAM allocated to the VM.hostPath
: VM file system directory to mount in the Docker container.path
: Path to thehostPath
directory.
Docker Compose specification
You need to provide instructions on running Docker containers and service configurations in the docker-compose.yaml
specification file, as stated in this Compose file reference
For more information on how to run multiple Docker containers, see Creating a VM from a Container Optimized Image with multiple Docker containers.
Sample Docker Compose specification
The Docker Compose specification is a YAML file named docker-compose.yaml
with the following contents:
version: '3.7'
services:
app1:
container_name: nginx
image: "nginx"
ports:
- "80:80"
restart: always
app2:
container_name: redis
image: "redis"
restart: always
volumes:
- /mnt/logs:/logs
- /mnt/data:/data
x-yc-disks:
- device_name: compute-disk-data
fs_type: ext4
host_path: /mnt/data
partition: 1
- device_name: compute-disk-data
fs_type: ext4
host_path: /mnt/logs
partition: 2
Where:
version
: Specification version tag the file should start with.services
: Section describing the services.container_name
: Docker container to run.image
: Docker image used to create and run the Docker container.ports
: Used for redirecting service ports. Use this format:<PC_port>:<container_port>
.restart
: Docker container restart policy settings.volumes
: Description of the volumes used in the Docker container.x-yc-disks
: Section describing the disks to attach. It is an extension of the Docker Compose specification . Used when preparing to run Docker containers, before running the Docker Compose file. Docker Compose skips this section.device_name
: Device name, different from the disk name. It is used on the VM to locate the disk in the/dev/disk/by-id/virtio-<device_name>
tree. You can set thedevice-name
parameter in flags and CLI commands for adding disks to a VM or in the management console when attaching a disk to a VM.fs_type
: File system type. The supported file systems are ext4 and xfs.host_path
: Directory to mount the disk to.partition
: Disk partition being used.