Introduction
Another article about an error message appear upon executing ‘docker-compose’ command. The execution is in a local device running using Microsoft Windows operating system. Moreover, there is already a file which is important in order to run the ‘docker-compose command properly. It is a file with the name of ‘docker-compose.yml’ as a requirement in order to execute the command. So, the following is the actual content of the file ‘docker-compose.yml’ which is causing the error message to appear :
version: '3.3' services: db:
On the other hand, the following is the actual execution of the command with additional parameter of ‘build’ :
C:\repository\docker\docker-image-build-with-docker-compose>docker-compose build yaml: line 2: mapping values are not allowed in this context C:\repository\docker\docker-image-build-with-docker-compose>
As it exist in the output of the above command execution, there is a specific error message appear. That error message is pointing out to the specific line. That is in the second line. So, the value for the ‘service’ definition’s value is incorrect. It seems that the format will not allow another value which is using to define a certain key which is ‘db:’.
How to Solve Error Message mapping values are not allowed in this context when running ‘docker-compose build’ Command
Following after the error appear in the previous part, the solution for solving the problem will be just remove the value ‘db:’ of the ‘services’ key definition. So, the following are steps for solving the problem or the error message appear :
-
First of all, try to move the value of the ‘services’ key definition. At this time, the revision is just to move ‘db:’ value into the next line as follows :
version: '3.3' services: db:
Execute the command ‘docker-compose build’ once more. Below is the execution of the command :
C:\repository\docker\docker-image-build-with-docker-compose>docker-compose build services must be a mapping C:\repository\docker\docker-image-build-with-docker-compose>
Unfortunately, the result is triggering another error message. In summary, the revision above is making the ‘service’ key definition is considered not a mapping. It means, moving it in the same or or in the different row below will still generate an error. Although, it is a different error.
-
After that, try to revise it once more by adding an additional indentation for the ‘db:’ value of the ‘services:’ key definition. In this context, the editing process of ‘docker-compose.yml’ is using Visual Code Editor. So, the revision will be as in the following display :
version: '3.3' services: db:
Soon after that, just execute the ‘docker-compose build’ command once more. Apparently, it is still trigger an error as follows :
C:\repository\docker\docker-image-build-with-docker-compose>docker-compose build services.db must be a mapping C:\repository\docker\docker-image-build-with-docker-compose>
-
Next step, do another revision. It is because the above step is still generating error. So, the following is another attempt to revise the ‘docker-compose.yml’ as follows :
version: '3.3' services: db: images: mysql
So, there is an additional line which is specifying the image. Just look at the documentation for list of key or attribute which is available for each services. It is available in the Docker documentation page specifically discussing about compose file as exist in this link. After revision, just execute the command once more as follows :
C:\repository\docker\docker-image-build-with-docker-compose>docker-compose build services.db Additional property images is not allowed C:\repository\docker\docker-image-build-with-docker-compose>
Unfortunately, it is still end with another failure. As it appear in the above output of the command execution. In order to solve it, just change the property of the ‘services’. The reason is because the property images is not available for the ‘services’ component. So, for this type of error, the solution is actually exist in another article. That article is an article with the title of ‘How to Solve Error Message services.db Additional property images is not allowed when running ‘docker-compose build’ Command in Microsoft Windows’ in this link.
-
Last step, referring to the article, just revise it as follows :
version: '3.3' services: db: image: mysql
-
Finally, after the revision, execute the command once more. If nothing goes wrong, the error message is finally no longer exist. As in the following command execution :
C:\repository\docker\docker-image-build-with-docker-compose>docker-compose build C:\repository\docker\docker-image-build-with-docker-compose>
In the end, the output result and also the revision of the above ‘docker-compose.yml’ will have a similar one as exist in the article in this link. That link is an article with the title of ‘How to Solve Error Message services.db Additional property images is not allowed when running ‘docker-compose build’ Command in Microsoft Windows’ as additional reference for solving the problem.