Reputation: 31651
I'm trying to build a docker image with my application in Gitlab continuous integration using the jib Maven plugin, but I can't get the plugin connect to the docker daemon using the dind (docker-in-docker) service. Currently I'm using this configuration in my gitlab-ci.yml file:
deploy:mvn:
image: maven:3.6.3-jdk-8-openj9
stage: deploy
services:
- docker:dind
script:
- mvn compile jib:dockerBuild
This is the error I get:
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.9.11:dockerBuild (default-cli) on project my-application: Build to Docker daemon failed, perhaps you should make sure Docker is installed and you have correct privileges to run it -> [Help 1]
UPDATE
I updated to 2.2.0 and it's running locally. I added the docker images
command before and the plugin seems not to be able to find the docker command in Gitlab CI:
$ docker images && mvn compile jib:dockerBuild /bin/bash: line 97: docker: command not found
This is the configuration for the jib plugin:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<from>
<image>adoptopenjdk/openjdk11:alpine-jre</image>
</from>
<to>
<image>my-application:latest</image>
</to>
<container>
<entrypoint>
<shell>sh</shell>
<option>-c</option>
<arg>chmod +x /entrypoint.sh && sync && /entrypoint.sh</arg>
</entrypoint>
<ports>
<port>8080</port>
</ports>
<environment>
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
<JHIPSTER_SLEEP>0</JHIPSTER_SLEEP>
</environment>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
</container>
</configuration>
</plugin>
Upvotes: 3
Views: 6816
Reputation: 4306
the plugin seems not to be able to find the docker command in Gitlab CI:
No, it is not Jib but /bin/bash
that cannot find the docker
command. Even before using Jib, you don't have docker
available. Take a closer look at the error message.
$ docker images && mvn compile jib:dockerBuild /bin/bash: line 97: docker: command not found
For example, on my Linux, if I try a command foo
that doesn't exist in a shell script, it outputs the same message.
$ /bin/bash -c "foo && mvn -v"
/bin/bash: line 1: foo: command not found
Therefore, the following command without mvn
will fail with the same error.
script:
- docker images
This proves that either docker
doesn't exist in your GitLab runtime environment or is not on the PATH
environment variable.
UPDATE
Updating my answer, since you answered that you now use jib:build
instead of jib:dockerBuild
.
If you use jib:build
, you don't even need Docker. Jib doesn't require Docker when building and pushing an image to a remote registry with jib:build
. Therefore, you can completely forget about setting up Docker and remove docker:dind
and export DOCKER_HOST
:
mvn compile jib:build -Djib.to.auth.username=$DOCKER_REGISTRY_USER -Djib.to.auth.password=$DOCKER_REGISTRY_PWD
Upvotes: 2
Reputation: 31651
Finally this is the configuration I got it working with:
services:
- docker:dind
deploy:mvn:
image: maven:3.6.3-jdk-8-openj9
stage: deploy
script:
- export DOCKER_HOST=tcp://docker:2375
- mvn compile jib:build -Djib.to.auth.username=$DOCKER_REGISTRY_USER -Djib.to.auth.password=$DOCKER_REGISTRY_PWD
only:
- tags
Apart from using the Docker in Docker service I needed to establish the DOCKER_HOST environment variable and also pass the credentials to my mvn jib:build
command. I stored the credentials in CI settings, as environment variables. Thanks @Chanseok Oh for your help.
See also:
Upvotes: 0