fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 642 forks source link

Error: "<image> must have a non-null <name>" #614

Open mcapitanio opened 7 years ago

mcapitanio commented 7 years ago

Description

I have define this plugin section:

<plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.17.2</version>
                <configuration>
                    <images>
                        <image>
                            <alias>galan</alias>
                            <name>cdp/galan</name>
                            <external>
                                <type>compose</type>
                                <basedir>docker</basedir>
                                <composeFile>docker-compose.yml</composeFile>
                            </external>
                        </image>
                    </images>
                </configuration>
</plugin>

Info

When I do:

mvn clean docker:build

I get the following error:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.17.2:build (default-cli) on project   galileo-anagrafica-rapporto-services: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.17.2:build failed: Configuration error: <image> must have a non-null <name> -> [Help 1]
rhuss commented 7 years ago

Thanks for the bug report. Any chance that you could share the project so that I could reproduce it ?

LorenzoBettini commented 7 years ago

I had a similar problem when my docker-compose.yml contained a build instruction. If I just refer to an image everything is fine...

however, I don't understand if all the other configurations work... I tried to wait for a condition in the section but with docker compose it looks like it is ignored...

longtu commented 7 years ago

I had a same issue. I'm wondering if docker-compose actually works here given it fails with such a simple configuration.

rhuss commented 7 years ago

@longtu @LorenzoBettini @mcapitanio thanks for the feedback. It really would help me, if you could share your docker-compose.yml files to reproduce this (as it works for the sample we have in samples/docker-compose, even when I add a build: section.

longtu commented 7 years ago

@rhuss Thanks for your instant reply. Here is my docker-compose file: version: '2'

services:

mysqlone: build: context: . dockerfile: mySQLDockerfile ports:

LorenzoBettini commented 7 years ago

@rhuss sorry, too much time has passed and I don't remember the details... if I'm not wrong, I was not giving any alias, so probably that was the real problem...

habzitouni commented 7 years ago

Hi, @rhuss : i have the very same issue with the 0.20.0 version of the plugin. Any update on the source of the problem ?

ustitc commented 7 years ago

@rhuss reproduced same issue in two cases by:

  1. Not using <alias> in the <image>
  2. Using container_name in docker-compose and <name> in pom.xml at the same time

Hope this will help.

upd: for the second case using of

<run>
     <namingStrategy>alias</namingStrategy>
</run>

fixes the issue

jordanglassman commented 6 years ago

Simple reproducing case here. Workaround is to include an image along with the build.

Dockerfile:

FROM redis
CMD redis-cli

pom.xml excerpt:

                <configuration>
                    <images>
                        <image>
                            <alias>my-redis</alias>
                            <name>my-redis</name>
                            <external>
                                <type>compose</type>
                                <basedir>.</basedir>
                                <composeFile>docker-compose.yaml</composeFile>
                            </external>
                        </image>
                    </images>
                </configuration>

docker-compose.yaml:

version: '2.1'
services:
  my-redis:
    build:
      context: .

  other-redis:
    build:
      context: .

Out:

$ mvn io.fabric8:docker-maven-plugin:0.22.1:build
...
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:build (default-cli) on project sandbox: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.22.1:build failed: Configuration error: <image> must have a non-null <name> -> [Help 1]
...
$ docker --version && docker-compose --version
Docker version 17.09.0-ce, build afdb6d4
docker-compose version 1.16.1, build 6d1ac21
timothybasanov commented 6 years ago

Yep. Looks like I'm affected as well. I debugged plugin code a bit (turns out it's as easy as use mvnDebug instead of mvn on the cmd line):

At least one NPE issue is here io.fabric8.maven.docker.config.handler.compose.DockerComposeConfigHandler#getImageName My workaround was to set pom.xml/alias to match “name” from docker-compose (for the image that requires a build and is not just pulled so it does not have "image"), then pom.xml/name would be used for that image and it can be non-null.

Unfortunately in my case there were some weird issues around <wait/> configs, so I ended up switching to exec plugin with shell scripts calling docker-compose directly.

Vamillion commented 6 years ago

Hello everyone. Unfortunately I encountered the same problem. Is there already a fix or workaround for the problem?

In addition, I noticed that the plugin unfortunately does not yet support compose files of version 3. Will this be added?

rhuss commented 6 years ago

@Vamillion yeah, you right, our compose support needs some polishing and more love. we are all super busy and so compose dropped a bit off. Sorry about that.

Currently, we have no concrete plans for composing version 3 but would be super happy if someone would help with this. We are constantly integration PR (though the queue piled up again a bit, eventually we get them merged more or less all of them).

So if you (or anybody else) feels fancy to polish the compose support, that would be awesome ;-)

Vamillion commented 6 years ago

@rhuss First of all, thank you very much for your quick reply. I think it's because I'm still a bit fresh on the road with regard to container management with Docker that I can't give you so much help in such a hurry. Should I see anything, however, I will get in touch with you. The same will probably also apply to a workaround for the error described above.

Vamillion commented 6 years ago

Hello again,

apparently it is because there is no image name listed within the docker-compose.yml. I don't know, if the guys above checked that out?

I checked that with and without the <name> Tag in the POM. It seems that only the image name within the compose file is relevant.

I don't know if it's just a workaround, but I'm able to create within Netbeans without any problems. The dependencies are the following : <dependency> <groupId>io.fabric8</groupId> <artifactId>run-java-sh</artifactId> <version>1.2.2</version> </dependency>

<image>
                                    <alias>secunym-pss-db</alias>
                                    <!--<name>vamillion/secunym-pss-db:latest</name>-->

                                    <external>
                                        <type>compose</type>
                                        <basedir>${project.basedir}/src/test/resources/docker</basedir>
                                        <composeFile>docker-compose.yml</composeFile>
                                    </external>
                                </image>

                                <image>
                                    <alias>secunym-pss-application</alias>
                                    <name>vamillion/secunym-pss-application:latest</name>

                                    <external>
                                        <type>compose</type>
                                        <basedir>${project.basedir}/src/test/resources/docker</basedir>
                                    </external>

In addition a part of the Compose Files:

secunym-dcc-application:
image: xxx/secunym-dcc-application
build:
context: ./dockerDCC/app/

    networks:
        secunym-systemtest-network:
            aliases:
                - secunym-dcc-app
            ipv4_address: xxx.xxx.xx.xx

    ports:
        - "28080:8080"
        - "28181:8181"

    depends_on:
        - secunym-dcc-db

Unfortunately networking is not supported by the plugin, so I have to think about something now.

I'm sorry, if the formatting is not correct. I'm new at GitHub and i didn't had the time to check out the manuels.

althaf-java commented 5 years ago

I had the same issue. The service name in the docker-compose.xml was wrong and not matching with the maven artifact name. I kept both of them same name and it worked.

docker-compose.xml services: some-other-name:

nikleo-eng commented 2 years ago

With Windows OS, I have faced the same issue with a local builded Dockerfile and not only with a pulled image; fortunally I have found a simple workaround, that works perfectly with the build goal of the plugin.

Plugin configuration in pom.xml:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.39.1</version>
    <configuration>
        <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
        <images>
            <image>
                <alias>${project.artifactId}</alias>
                <name>
                    ${project.groupId}/${project.artifactId}:${project.version}
                </name>
                <external>
                    <type>compose</type>
                    <basedir>${project.basedir}</basedir>
                    <composeFile>docker-compose.yml</composeFile>
                </external>
                <run>
                    <wait>
                        <log>Application Started</log>
                        <time>60</time>
                    </wait>
                </run>
            </image>
        </images>
    </configuration>
    <executions>
        <execution>
            <id>docker-build-image</id>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
        <execution>
            <id>docker-verify</id>
            <phase>verify</phase>
            <goals>
                <goal>start</goal>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Referenced docker-compose.yml:

version: '2'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    # You can now specify both a build and an image key if you're using the new file format.
    # docker-compose build will build the image and tag it with the name you've specified,
    # while docker-compose pull will attempt to pull it.
    # https://github.com/docker/compose/releases/tag/1.6.0
    # Workaround for issues:
    # https://github.com/fabric8io/docker-maven-plugin/issues/614
    # https://github.com/fabric8io/docker-maven-plugin/issues/909
    image: app:latest
    container_name: app_container
    networks:
      - custom-network
    depends_on:
      - mysql
  mysql:
    image: mysql:8.0.28
    container_name: mysql_container
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=password
    ports:
      - '3306:3306'
    expose:
      - '3306'
    networks:
      - custom-network

networks:
  custom-network:
    driver: bridge 

(the referenced Dockerfile of the app service is not important for the replica of this issue)

The configuration line image: app:latest does all: it is a workaround for the issue and it is not used at all in the build goal of the plugin, that build the local referenced Dockerfile.