Introduction
This article is focusing on how to solve a specific error message. In this case, the error message exist upon the execution of a certain command. In this context, it is the execution of ‘docker-compose’ command. Furthermore, the execution of the ‘docker-compose’ command is in a local device running using Microsoft Windows operating system. So, there is already a file with the name of ‘docker-compose.yml’ exist in a certain folder location. It is a necessary file for the ‘docker-compose’ command with the ‘build’ additional parameter to runner properly. So, the error appear specifically when the execution of the ‘docker-compose’ command has the ‘build’ additional parameter for building local docker image. The following 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>
Before going on to solve the problem, what does the ‘docker-compose.yml’ file looks like ?. Below is the actual content of the ‘docker-compose.yml’ file :
version: '3.3' services:
The above ‘docker-compose.yml’ file only consist of two lines. The second line is actually triggering the error message. It appears that the ‘services’ definition in that format it is not really a mapping. Well, it is obvious since the definition of the ‘services’ does not have any value at all. So, what is the solution in order to solve the problem ?. The solution is actually very easy. Just add another content acts as a value of the ‘services’ definition. Take a look at the next part to look the process for solving the problems.
How to Solve Error Message services must be a mapping when running docker-compose Command
For an example, just add a database service in this context. Just choose any service name for defining the service. For an example, in this context, for a database service, just choose ‘db’ as its name. Below are step by step revision of the ‘docker-compose.yml’ until the error message is actually disappear. Those steps exist as follows :
-
So, the first revision of the above content of the ‘docker-compose.yml’ exist as follows. It is simply by adding a value of ‘db’ into the services definition :
version: '3.3' services: db
Below, it is the execution of the ‘docker-compose.yml’ command using the above script :
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>
Apparently, the above revision is not working. So, continuing on to the following revision step :
-
The second revision is actually adding double colon to the service name of ‘db’ below. So, the revision will be as follow : In the hope of the revision will solve the problem as exist below :
version: '3.3' services: db:
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>
The above error has a solution exist in the previous article. It is an article with the title of ‘How to Solve Error Message mapping values are not allowed in this context when running ‘docker-compose build’ Command in Microsoft Windows’. Furthermore, the article exist in this link.
-
According to the article mentioned before, the following will be the final revision in order to avoid more error messages : Using the above ‘docker-compose.yml’ file’, below is the command execution for building the local docker images :
version: '3.3' services: db: image: mysql
-
So, below is another attempt to execute the command after revising it accordingly using the above revision :
C:\repository\docker\docker-image-build-with-docker-compose>docker-compose build C:\repository\docker\docker-image-build-with-docker-compose>
At last, no error message appear further. Although it does not affect anything and it does not have any output message after the command execution, at least it is running properly.