Data Only Containers/No Run Containers
Problem
I propose that Compose be able to support a way to create volume containers that never run. Right now, if you want to describe a volume container in your figfile, you must expect it to run. The best you can do is [code block] But it shouldn't be necessary to run a DVC at all. In the commandline Docker client I can do: [code block] It's admittedly a little strange to have to provide an entrypoint to `scratch`, but it doesn't ever run, so it doesn't make a difference. It would be nice to be able to do this in Compose as well. [code block] Related: - #697 asks to be able to run a subset of containers. This is similar in that it asks not to run a container. Perhaps this provides a use case for that, but that issue still implies that the containers can be run. This proposal is to mark containers for creation, but never to run them. - #613 - Despite the similar title this is a feature request with significantly different implications.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement Support for Data-Only Containers in Docker Compose
Currently, Docker Compose requires all defined services to run, which limits the ability to create volume containers that are only intended for data storage. This behavior is due to the design of Docker Compose, where every service defined in the compose file is treated as a runnable container, even if the primary purpose is to manage volumes.
Awaiting Verification
Be the first to verify this fix
- 1
Define a New Container Type
Modify the Docker Compose specification to include a new container type that allows for the definition of data-only containers (DVCs) that do not run. This could be achieved by introducing a 'dvc' service type.
yamlversion: '3.8' services: my_data_container: image: scratch volumes: - my_volume:/data deploy: replicas: 0 - 2
Update Docker Compose CLI
Enhance the Docker Compose CLI to recognize the new 'dvc' service type and ensure that it does not attempt to start these containers during the 'up' command. This will involve modifying the command handling logic to skip DVCs.
pythonif service.type == 'dvc': continue - 3
Document the New Feature
Update the Docker Compose documentation to include information on how to define and use data-only containers. This should include examples and best practices for managing volumes without running containers.
yaml### Data-Only Container Example version: '3.8' services: my_data_container: type: dvc volumes: - my_volume:/data - 4
Test the Implementation
Create unit tests and integration tests to ensure that the new DVC functionality works as expected. Verify that DVCs are created correctly and do not run when executing 'docker-compose up'.
pythondef test_dvc_creation(): assert run_command('docker-compose up') does not start dvc containers
Validation
To confirm the fix worked, define a service as a data-only container in a Docker Compose file, run 'docker-compose up', and ensure that the container is created without starting. Verify that the volume is accessible as expected.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep