I have a docker compose file that is transferred from previous vendor and this is something like that
api-service:
image: ${IMAGE}
ports:
- "8080:8080"
environment:
SPRING_PROFILES_ACTIVE: ${PROFILE}
log_driver: awslogs
When I try to build with this file, it cannot be built by compose. The error message is (root) Additional property api-service is not allowed".
I think this file is not in correct format for docker compose. I want to know that is there any configuration is need to make that file work or is there some kind of docker feature that can combine partial docker compose file like that?
I gonna add more information. Currently I have 2 files like this under different service names and my idea is that there must be a parent docker compose file that will include/import those 2 files to form a fully working docker compose file. I already read docker compose documentation for that kind of feature and haven’t found anything that close to something like this.
2
Answers
Docker compose files must have the two top-level keys
version
andservices
.version
is a string andservices
is a dict of all services. You snippet looks like a single service definition.https://docs.docker.com/compose/compose-file/compose-file-v3/
A minimal compose file:
That looks like a "version 1" Compose file. This was the first version of the Compose YAML file format. It just contains the list of service definitions at the top level; it does not have a
version:
tag or aservices:
block header; and it has no way to declarenetworks:
orvolumes:
.There are also two versions of the Compose tool itself. As of June 2023 Docker discontinued support for the older (Python-based) version. If you can run
docker compose
with a space, you have the newer version. However, the Compose tool version 2 doesn’t support Compose file version 1.If you have the newer Compose tool, the fastest path to get something close to working is to indent the entire file by two spaces, and then add
services:
as a first line above it.If you want to keep compatibility with the older Compose tool, you will also need a
version: '2.4'
orversion: '3.8'
line, typically at the very top of the file.In all of these file formats, the way to specify the logging driver has changed. The driver setting is under a
logging:
block (link to Compose file v3 docs; same setting in Compose file v2 and Compose Specification).So I might translate this file to