0

I'm trying to build a docker image using a variable for my FROM docker base image

Docker Compose

version: "3.7"
services:
  app:
    build:
      context: "."
      dockerfile: .docker/Dockerfile
    working_dir: /ionic-app
    environment:
      NODE_VER: 12.16.0

Dockerfile

# Create Basic docker file 
FROM node:${NODE_VER}

But this doesn't work I get, I've read that this isn't possible or that you need to add build arguments for this to work?

ERROR: Service 'ionic-app' failed to build: invalid reference format

Is this possible? I want to make it so when Node updates their LTS version I'll easily be able to change versions via arguments.

1 Answer 1

1

You can do it using arguments:

Dockerfile

ARG NODE_VER=latest
FROM node:$NODE_VER
...

Docker Compose

version: "3.7"
services:
  app:
    build:
      context: "."
      dockerfile: .docker/Dockerfile
      args:
        NODE_VER: "12.16.0"
    working_dir: /ionic-app
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.