Quotes automatically removed from docker-compose.prod.yml file, causing port issue

I am using the .🔨-create-production-image script to build my application container and generate the docker-compose.prod.yml file. However, it seems to me that the quotes (or double-quotes) surrounding the values are removed and do not appear in the generated docker-compose.prod.yml.

This is especially annoying for the “ports” definition. Here is a quote from the compose file reference page:

When mapping ports in the HOST:CONTAINER format, you may experience erroneous results when using a container port lower than 60, because YAML parses numbers in the format xx:yy as a base-60 value. For this reason, we recommend always explicitly specifying your port mappings as strings.

So here is an example. I have a container which needs the port 21 to be exposed:

  ftp_server:
    image: zhabba/pure-ftpd-arm64
    container_name: ftp_admin
    ports:
      - "21:21"
      - "30000-30009:30000-30009"

Once the .🔨-create-production-image script has been executed, the docker-compose.prod.yml file looks like this:

  ftp_server:
    image: zhabba/pure-ftpd-arm64
    container_name: ftp_admin
    ports:
      - 21:21
      - 30000-30009:30000-30009

Finally, when running this on my board, I cannot access the FTP server. A docker container inspect ftp_admin reveals the following:

[
    {
        [...]
        "HostConfig": {
            [...]
            "PortBindings": {
                "1281/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": ""
                    }
                ],
                "30000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "30000"
                    }
                ],
[...]

The port 21 disappeared and was replaced by the port 1281… which exactly corresponds to “21:21” interpreted as a base-60 value.

I temporarily fixed the issue by manually adding the quotes around 21:21 in the docker-compose.prod.yml file, but I know I will someday forget to do it… Is there another way to fix it?

I have been browsing the community for a while, but I still hope this is no duplicate…

Greetings @val.lec,

Thank you for reporting this. As you said I don’t believe anyone has mentioned this behavior before. I’ll bring this to the attention of our IDE extensions team.

Best Regards,
Jeremias

The issue was brought up with our team and an open issue was created here: Quotes automatically removed from docker-compose.prod.yml file, causing port issue · Issue #167 · toradex/vscode-torizon-templates · GitHub

Some investigation is still needed. But it looks like the YAML parser is causing this behavior. It understands "21:21" is a string and that the quotes are not “needed”, so it just removes what it sees as redundant quotes. This then clashes with how compose interprets this string.

The team will need to see if this behavior of the YAML parser can be changed in some way.

Best Regards,
Jeremias

Ok, thank you very much for your support!

Best regards,
Val