Spring Cloud+docker Creating a microservices container instance

Source: Internet
Author: User
Tags docker ps docker hub docker run

1. Configure Windows Environment

Install the Windows version of Docker

This step can self-Baidu installation method.

Configuring MAVEN Environment variables

Add Maven's Bin directory to path, under normal circumstances, MAVEN's maven_home already exists, on this basis add/bin is MAVEN's PATH environment variable

Add in Path

Perform mvn--version on the command line to check if MAVEN is configured correctly

2. configuring IntelliJ Idea

Open windows version of Docker, tick expose daemon on tcp://localhost:2375 without TLS in the Settings window

Configuring Docker in IntelliJ

The file–>settings–>build,execution,deployment–>docker–> is configured as follows:

The Docker tool window will automatically appear at the bottom after the configuration is complete

If it does not appear automatically, you can use the View–>tool windows–>docker on the Idea top toolbar

3. Create a spring-clound project

Create a spring Clound Registration center project, the steps can be Baidu itself. Say the point, after creation, add the following dependencies in Pom.xml.

<!--tag::p lugin[]-
<plugin>
<groupId>com.spotify</groupId>
<artifactid>docker-maven-plugin</artifactid>
<version>0.4.3</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactid}</imageName>
<dockerdirectory>src/main/docker</dockerdirectory>
<resources>
<resource>
<TargetPath>/</TargetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalname}.jar</include>
</Resource>
</Resources>
</Configuration>
</Plugin>
<!--end::p lugin[]--

4. Writing Dockerfile

Create a docker directory in the main directory and create a dockerfile file in the Docker directory

The contents of the file are as follows:

Java:8
VOLUME/tmp
Application-0.0.1.jar App.jar
#RUN bash-c ' Touch/app.jar '
["Java","-djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
8888

Click on the dockerfile's small triangle to pop up the menu below

Click "Edit ' Docker/dockerfile-reg", pop up the following window, can refer to the contents of the window to configure

5. Build the jar package

Before executing the dockerfile, you need to ensure that the project's jar package is present, and that the dockerfile is in the sibling directory.

Generate jar packages from MVN package with command

You can see the following results when you are done

Copy the jar package to Dockerfile's sibling directory

6. Executive Dockerfile

When Dockerfile is selected, right-click, and then tap Run/dockerfile-reg

The process log is displayed in the Output window

7. View Docker images

Once the deploy is complete, you can use the Docker command-line tool to view existing images image information

Docker images

8. Run the Docker container

Create a Docker container by executing the following command

Docker Run–d–p 8888:8888 Springcloundimage

Viewing a running Docker container with Docker PS

You can see the container we just created.

On-premises access to http://localhost:8888 can see the spring Cloud's Registration Center page

9. Upload the Docker image

Before uploading, you need to make a small change to the name of the image, such as

Once the modifications are complete, rerun the Dockerfile and view the Docker images to see the new image

Log on to the Docker hub

Push the image to the Docker hub when you are done

Log on to the Docker hub website to view

This image already exists, local pull

Call it


Spring Cloud+docker Creating a microservices container instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.