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

dockerfile_inline limitations #18566

Closed
1 task done
ToshY opened this issue Nov 1, 2023 · 7 comments
Closed
1 task done

dockerfile_inline limitations #18566

ToshY opened this issue Nov 1, 2023 · 7 comments
Labels
area/compose Relates to docker-compose.yml spec or docker-compose binary lifecycle/locked

Comments

@ToshY
Copy link

ToshY commented Nov 1, 2023

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

Information is incorrect

Description

The dockerfile_inline documentation shows a basic example on how to use multi-line syntax to pass the contents of a Dockerfile, but it seems that it cannot replace a Dockerfile out of the box, as I noticed instructions like ARG do not work.

I've noticed that it was already stated in compose-spec/compose-spec#298 (comment) that the use-case for dockerfile_inline would be for simple commands, so I think it doesn't hurt to explicitly mention this in the documentation.

Location

https://docs.docker.com/compose/compose-file/build/#dockerfile_inline

Suggestion

Add a note to the dockerfile_inline section explicitly stating that it's use-case is for simple instructions only and that it cannot fully replace using a separate Dockerfile.

@ToshY ToshY added the status/triage Needs triage label Nov 1, 2023
@aevesdocker aevesdocker added area/compose Relates to docker-compose.yml spec or docker-compose binary and removed status/triage Needs triage labels Nov 2, 2023
@denzuko
Copy link

denzuko commented Nov 4, 2023

In an ecosystem where buildpacks, helm charts, and the like. I would argue for the opposite and allow it to fully replace a Dockerfile.

@ndeloof
Copy link
Contributor

ndeloof commented Nov 6, 2023

ARG is well supported, but - like when using a plain Dockerfile - you need to inform Compose about build args and value to be set:

$  cat compose.yaml 
services:
  test:
    build:
      dockerfile_inline: |
        FROM alpine
        ARG FOO
        RUN echo $FOO > /foo
      args:
        - FOO
$ FOO=BAR docker compose build
[+] Building 0.1s (6/6) FINISHED                                                                                                docker:desktop-linux
 => [test internal] load .dockerignore                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                 0.0s
 => [test internal] load build definition from Dockerfile                                                                                       0.0s
 => => transferring dockerfile: 114B                                                                                                            0.0s
 => [test internal] load metadata for docker.io/library/alpine:latest                                                                           0.0s
 => CACHED [test 1/2] FROM docker.io/library/alpine                                                                                             0.0s
 => [test 2/2] RUN echo BAR > /foo                                                                                                              0.1s
...

@ndeloof
Copy link
Contributor

ndeloof commented Nov 6, 2023

Closing this issue as "work as documented"

@ndeloof ndeloof closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2023
@ToshY
Copy link
Author

ToshY commented Nov 6, 2023

@ndeloof

ARG is well supported, but - like when using a plain Dockerfile - you need to inform Compose about build args and value to be set

Here's a simple example which uses ARG before FROM and includes a default value.

Dockerfile

ARG PHP_VERSION=8.2
FROM php:${PHP_VERSION}

This does not work with dockerfile_inline.

docker-compose.yml

version: '3.9'

services:
  php:
    build:
      context: .
      dockerfile_inline: |
        ARG PHP_VERSION=8.2
        FROM php:${PHP_VERSION}
$ docker compose up -d
WARN[0000] The "PHP_VERSION" variable is not set. Defaulting to a blank string.
[+] Building 0.0s (2/2) FINISHED                                                                                                                                             docker:default
 => [php internal] load build definition from Dockerfile                                                                                                                               0.0s
 => => transferring dockerfile: 68B                                                                                                                                                    0.0s
 => [php internal] load .dockerignore                                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                                        0.0s
failed to solve: failed to parse stage name "php:": invalid reference format

@ndeloof
Copy link
Contributor

ndeloof commented Nov 6, 2023

in your example, FROM php:${PHP_VERSION} is interpolated by docker compose during parsing, as demonstrated by the warning message about unset variable. You need to double the dollar sign to prevent this:

      dockerfile_inline: |
        ARG PHP_VERSION=8.2
        FROM php:$${PHP_VERSION}

@ToshY
Copy link
Author

ToshY commented Nov 7, 2023

@ndeloof Thanks for the explanation!

@docker-robot
Copy link

docker-robot bot commented Dec 7, 2023

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.

/lifecycle locked

@docker-robot docker-robot bot locked and limited conversation to collaborators Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/compose Relates to docker-compose.yml spec or docker-compose binary lifecycle/locked
Projects
None yet
Development

No branches or pull requests

4 participants