Using the ARGS with an IMAGE in docker-compose

Hey guys,

docker -v
Docker version 1.12.1, build 23cf638, experimental

docker-compose -v
docker-compose version 1.8.0, build f3628c7

I’m attempting to get a docker-compose file working that uses the ARGs option along with the image option.

ERROR: The Compose file './docker-compose.yml' is invalid because: services.db.build contains unsupported option: 'image'

Here is the relevant part of my compose file:

   1 version: '2'                                                                     
   2 services:                                                                        
   3   db:                                                                            
   4     build:                                                                       
   5       image: postgres:9.4.1                                                      
   6       args:                                                                      
   7         POSTGRES_USER: 'special_user'                                                  
   8     volumes:                                                                     
   9       - postgres:/var/lib/postgresql/data                                        

Here in the docs, it seems to say you CAN use image with build, but it’s about creating an image not using one.

Can I somehow use ARGS along with an image in the compose file? The usecase for this is, that the postgres image uses onbuild or something, and requires build time variables to be entered in. So I can’t get the user to be created when I do docker-compose build db :frowning:

1 Like

You can use image and build side by side, but not one nested inside of the other like you have above. Note that image is a key of build in your example.

Hello,

$ docker -v
Docker version 1.12.5, build 7392c3b

$ docker-compose -v
docker-compose version 1.9.0, build 2585387

I am experiencing a similar problem. I understand the solution expressed above but haven’t found the correct syntax to do so.

version: '2'
services:
  myApp:
    image: ourPrivate/dockerImage
    build:
      args:
        domain: myapp.dev
    container_name: my-app
    stdin_open: true
    tty: true
    ports:
      - "80:80"
      - "443:443"
      - "3306:3306"
    links:
      - db
    volumes:
      - .:/var/www/html

  db:
    image: "mysql:5"
    environment:
      MYSQL_ROOT_PASSWORD: blahblah
      MYSQL_DATABASE: blah_db

Our docker hub hosted image is expecting a build argument to set the domain in apache for a dev environment. I have tried using the context flag under build but then it looks for a local dockerFile. I need to pass the build args to the remote image that gets pulled down.

Receiving this error:

ERROR: The Compose file is invalid because:
Service myApp has neither an image nor a build context specified. At least one must be provided.

Thank you in advance!

1 Like

Hello,

I’m receiving the same error message. My docker-compose.yml:

version: "3"

services:
  hub:
    image: selenium/hub
    ports:
      - "4444:4444"

  firefox:
    image: selenium/node-firefox
    build:
      args:
        FIREFOX_VERSION: "45.0.1"
    links: [hub]
    environment:
      - DBUS_SESSION_BUS_ADDRESS=/dev/null

Got:
# docker-compose up -d
ERROR: The Compose file is invalid because:
Service firefox has neither an image nor a build context specified. At least one must be provided.

Any idea?

Hi @mlcruz,

I found the way to do so.

Please find below a working Docker compose file with the args:

version: '3'
services:
  selenium-node-firefox:
image: selenium/node-firefox:latest
build:
  context: https://github.com/SeleniumHQ/docker-selenium.git
  dockerfile: NodeFirefox/Dockerfile
  args:
    FIREFOX_VERSION: 51.0.1
    GECKODRIVER_VERSION: 0.14.0
links:
  - selenium-hub:hub
environment:
  HUB_PORT_4444_TCP_ADDR: 'hub'
  HUB_PORT_4444_TCP_PORT: 4444
  NODE_MAX_INSTANCES: 3
  NODE_MAX_SESSION: 3
depends_on:
  - selenium-hub
  selenium-node-chrome:
image: selenium/node-chrome:latest
links:
  - selenium-hub:hub
environment:
  HUB_PORT_4444_TCP_ADDR: 'hub'
  HUB_PORT_4444_TCP_PORT: 4444
  NODE_MAX_INSTANCES: 3
  NODE_MAX_SESSION: 3
depends_on:
  - selenium-hub
  selenium-hub:
image: selenium/hub:latest
ports:
  - '4444:4444'
  nginx:
restart: always
image: travix/nginx:1.11.10-alpine
depends_on:
  - selenium-node-chrome
  - selenium-node-firefox
  - selenium-hub
links:
  - selenium-hub:hub
environment:
  OFFLOAD_TO_HOST: 'hub'
  OFFLOAD_TO_PORT: 4444
  SERVICE_NAME: 'selenium-hub'
  HEALTH_CHECK_PATH: '/status'
  ENFORCE_HTTPS: 'false'
volumes:
  - ./private:/etc/ssl/private
ports:
  - '80:4444'
  - '443:443'

However, I am facing another issue.

It seems that Docker-compose cannot resolve the file generate_config.

I will investigate it a bit more for understanding why it doesn’t work.

1 Like

I found out why it doesn’t work. The context is the entire repository so all the paths are resolved from the root path of the repo. The solution would be to have the directory NodeFirefox in its own repository

I open an issue on the Docker Selenium repository: https://github.com/SeleniumHQ/docker-selenium/issues/596