docker-maven-plugin icon indicating copy to clipboard operation
docker-maven-plugin copied to clipboard

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

Open mcapitanio opened this issue 9 years ago • 16 comments

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]
  • d-m-p version : 0.17.2
  • Maven version (mvn -v) :
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: it_IT, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-45-generic", arch: "amd64", family: "unix"
  • Docker version :

mcapitanio avatar Nov 09 '16 06:11 mcapitanio

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

rhuss avatar Nov 11 '16 18:11 rhuss

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...

LorenzoBettini avatar Nov 24 '16 10:11 LorenzoBettini

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

longtu avatar Feb 17 '17 01:02 longtu

@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.

rhuss avatar Feb 17 '17 06:02 rhuss

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

services:

mysqlone: build: context: . dockerfile: mySQLDockerfile ports: - 33306:3306 volumes: - /mysql_data restart: always environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: database_name MYSQL_USER: test_user MYSQL_PASSWORD: test_password

longtu avatar Feb 17 '17 18:02 longtu

@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...

LorenzoBettini avatar Feb 20 '17 10:02 LorenzoBettini

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 ?

habzitouni avatar Jul 25 '17 15:07 habzitouni

@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

ustitc avatar Sep 15 '17 14:09 ustitc

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

jordanglassman avatar Nov 02 '17 18:11 jordanglassman

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.

timothybasanov avatar Jan 20 '18 01:01 timothybasanov

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?

Vamillion avatar Sep 21 '18 10:09 Vamillion

@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 ;-)

rhuss avatar Sep 21 '18 10:09 rhuss

@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 avatar Sep 21 '18 11:09 Vamillion

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.

Vamillion avatar Sep 21 '18 12:09 Vamillion

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:

althaf-java avatar Nov 09 '18 17:11 althaf-java

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.

nikleo-eng avatar Mar 14 '22 19:03 nikleo-eng