Skip to content

Cast issue on int64 after variable interpolation in docker-compose.yml #2730

Closed

Description

@tiry

I am using compose variable interpolation because I would like to make part of the compose template configurable.

This works for some parameters, however, there seems to be an issue with parameters that expect an integer value (tested against 1.5.2 and 1.6 dev).

Typically, if I want to change the cpu-shares parameter I end up with an error :

ERROR: json: cannot unmarshal string into Go value of type int64

Looking at what happens in interpolation.py and checking the content of the interpolation result:

  • when the cpu-shares is "hard coded" the resulting dict is

    { ... 'cpu_shares': 1024 ... }

  • when the cpu-shares is set to use a variable using cpu_shares: ${CPU_SHARES} the resulting dict is

    { ... 'cpu_shares': '1024' ... }

This looks to me like the root cause of the problem.

I am not sure what the best approach would be:

  • should I try to add a tentative cast after the Template(string).substitute ?
  • should I add some post processing in config.py or in validate_against_fields_schema ?

Activity

  1. dnephin commented on Jan 22, 2016

    @dnephin

    I don't know of a good way to handle problem at this time, but I think it's something that does need to be fixed. We have the same issue with boolean fields.

  2. tiry commented on Jan 25, 2016

    @tiry
    Author

    Just trying to discover the code and see how this could be fixed.

    Using Json Schema info

    In service_schema_v1.json the cpu_shares is defined as

    "cpu_shares": {"type": ["number", "string"]},
    

    I am not sure why "string" is accepted, based on what I can see in the docker run doc it should not be the case (but I may very well have missed something).

    I am asking because, if we had a single type in the schema, it could probably be used to do some automatic cast after the interpolation :

    • get the type of the field from the schema
    • do the cast from String as needed

    The conversion could also be done as an error handler for the jsonschema validator, but I like the idea that the "automatic cast" is only applied for "interpolated variables".

    Add conversion hint in the source template

    An other option would be to add some hints in the templatised config file (ex cpu_shares: int:${CPU_SHARES}), but this does not seems like a clean approach (+ it is redundant info).

  3. added 6 commits that reference this issue on Jan 26, 2016
  4. changed the title [-]Cast issue on int64 after variable interpolation in docker-compose.xml[/-] [+]Cast issue on int64 after variable interpolation in docker-compose.yml[/+] on Feb 9, 2016
  5. added 5 commits that reference this issue on Feb 22, 2016
  6. wu0407 commented on Apr 7, 2017

    @wu0407

    the similar problem,if i set

        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: 3
    

    docker-compose up end up

    json: cannot unmarshal number into Go value of type string
    

    docker version

    [root@docker deploy]# docker version
    Client:
     Version:      17.03.1-ce
     API version:  1.27
     Go version:   go1.7.5
     Git commit:   c6d412e
     Built:        Mon Mar 27 17:05:44 2017
     OS/Arch:      linux/amd64
    
    Server:
     Version:      17.03.1-ce
     API version:  1.27 (minimum version 1.12)
     Go version:   go1.7.5
     Git commit:   c6d412e
     Built:        Mon Mar 27 17:05:44 2017
     OS/Arch:      linux/amd64
     Experimental: false
    

    docker-compose version

    [root@docker deploy]# docker-compose version
    docker-compose version 1.12.0, build b31ff33
    docker-py version: 2.2.1
    CPython version: 2.7.13
    OpenSSL version: OpenSSL 1.0.1t  3 May 2016
    
  7. shouze commented on Jul 3, 2017

    @shouze

    @shin- @dnephin it's been a long time about that related issues of that kind.

    From now, will need to adapt in docker-compose & in go compose lib integrated into docker codebase.

    But prior to that, is there any consensus about casting variables or not according to schema types?

  8. added this to the 1.18.0 milestone on Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions