Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of key-value build args in docker-compose not working #2661

Closed
bilow-factual opened this issue Mar 5, 2018 · 3 comments
Closed

Parsing of key-value build args in docker-compose not working #2661

bilow-factual opened this issue Mar 5, 2018 · 3 comments

Comments

@bilow-factual
Copy link

Expected behavior

Should be able to specify build args as key-value pairs, strings with assignment, or strings without assignment, as in: https://docs.docker.com/compose/compose-file/#args

Actual behavior

Error below when passing build args as key-value pairs. See Dockerfile + docker-compose.yml below for more information:

ERROR: The Compose file './docker-compose.yml' is invalid because: services.dev.build.args contains {"goodbye": "bye"}, which is an invalid type, it should be a string

Information

Docker for Mac: version: 17.12.0-ce-mac55 (18467c0ae7afb7a736e304f991ccc1a61d67a4ab)
macOS: version 10.13.3 (build: 17D102)
logs: /tmp/F873DA0F-6DAF-44C1-A4D4-5154F96751D5/20180304-185129.tar.gz
[OK]     vpnkit
[OK]     vmnetd
[OK]     dns
[OK]     driver.amd64-linux
[OK]     app
[OK]     virtualization VT-X
[OK]     moby
[OK]     system
[OK]     moby-syslog
[OK]     kubernetes
[OK]     env
[OK]     virtualization kern.hv_support
[OK]     moby-console
[OK]     osxfs
[OK]     logs
[OK]     docker-cli
[OK]     disk

Steps to reproduce the behavior

Here's my docker-compose.yml

version: '3'
services:
  dev:
    build:
      context: .
      args:
        - hello=hi
        - goodbye: bye

and my Dockerfile

FROM ubuntu
ARG hello
ARG goodbye
RUN echo $hello
RUN echo $goodbye
  1. docker-compose up yields the error above, complaining about the type of the 'goodbye' build arg.
@thaJeztah
Copy link
Member

The build args can be either provided as a list, or as a mapping; referring to the docs:

Then specify the arguments under the build key. You can pass either a mapping or a list:

build:
  context: .
  args:
    buildno: 1
    password: secret

build:
  context: .
  args:
    - buildno=1
    - password=secret

You can omit the value when specifying a build argument, in which case its value at build time is the value in the environment where Compose is running.

args:
  - buildno
  - password

So either specify (list of strings):

args
  - key=value
  - key2

Or (mapping)

args
  key: value

The reason it's failing in your case is because you're trying to use a "map" (key: value) inside a list (starting with - )

Change your compose file to:

version: '3'
services:
  dev:
    build:
      context: .
      args:
        hello: hi
        goodbye: bye

Or

version: '3'
services:
  dev:
    build:
      context: .
      args:
        - hello=hi
        - goodbye=bye

And it should work

I'm closing this issue, because this doesn't look like a bug, but feel free to continue the conversation 👍

@bilow-factual
Copy link
Author

Ah, oops. Thank you.

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked

@docker docker locked and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants