Publishing images

In order to publish a Docker image in Docker Hub, you will need to create an account and then log into Docker Hub using the terminal with the docker login command. After entering your credentials, you should see an output similar to the following code in the terminal:

$ docker login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: enriquezrene
Password:
Login Succeeded

Now that you're logged in, you can push the image into the registry using the docker push command, as shown in the following code:

$ docker push <docker-hub-username/docker-image:tag-version>

When the tag version is not specified, the latest value is used by default. In our case, a pretty small change should be applied to the build.gradle file to append the docker-hub-username prefix required by Docker Hub, as shown in the following code:

docker 
{
name "enriquezrene/spring-boot-${jar.baseName}:${version}"
files jar.archivePath
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}

After generating the image again, you should log into Docker Hub from the terminal using the docker login command, and the image can be pushed later, as shown in the following code:

# Login into Docker Hub
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: <username>
Password: <password>
Login Succeeded
# Push the image
$ docker push enriquezrene/spring-boot-banking-app:1.0

Once the image has been pushed, you can pull it and run a container in any other computer by typing the following command:

$ docker run enriquezrene/spring-boot:1.0

This will download the image from Docker Hub and run the application locally. In the same way, we can repeat this process to deploy an application in any environment.

The following screenshot shows how the pushed image looks on Docker Hub:

Docker image pushed into Docker Hub

The push command should be automated using continuous integration servers. A good idea is to execute this command once a branch is merged into a master tag or a new tag is created in the version control system. You should always avoid using the default latest tag value. Instead, you should create version numbers by yourself using an automatic process, as we did using the Gradle plugin in the previous section.

The integrated plugin also has the ability to push images using the dockerPush Gradle task.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.252.204