java version of the e-commerce spring cloud distributed micro social service b2b2c electricity supplier (XI) docker spring cloud deployment project

A, docker Profile

Docker is an open source engine, you can easily create a lightweight for any application, portable, self-contained container. Developers test container in a notebook compiled by the batch can be deployed in a production environment, including the VMs (virtual machines), bare metal, OpenStack cluster and other basic application platform. 
Docker commonly used in the following scenarios:

  • Automated packaging and publishing web applications;
  • Automated testing and continuous integration, publishing;
  • Deployment and tuning the database or other back-office applications in a service-oriented environment;
  • Recompile or extend an existing OpenShift or Cloud Foundry PaaS platform to build their own environment.

Docker's advantage

  • 1, a simplified procedure: 
    Docker allows developers to package their applications as well as a portable container to the dependencies, and then posted to any popular Linux machine, you can virtualize. Docker changed the way virtualization, enabling developers to put their results directly to the Docker for management. Convenient Docker already is the biggest advantage of, used to take days or even weeks with the task in handling Docker containers, only take seconds to complete.

  • 2, avoid selecting phobia: 
    If you have a choice phobia, or experienced patients. Docker help you pack your tangle! For example Docker mirror; Docker mirror configuration and includes the operating environment, it is possible to simplify the deployment of multiple applications Docker working examples. Such as Web applications, back-end applications, database applications, large data applications such as Hadoop cluster, message queues, etc., can be packaged into a single image deployment.

  • 3, save money: 
    on the one hand, the cloud computing era, so that developers do not have effect in order to pursue high configuration hardware, Docker change the inevitable high price-performance mindset. Docker combined with cloud to cloud space to be more fully utilized. Not only solved the problem of hardware management, but also changed the way of virtualization.

Text above with reference to the relevant articles; the other, installation, and basic usage on docker see the relevant tutorial.

Second, prepare for work

Environmental conditions:

  • linux system is not recommended windows
  • docker latest version
  • jdk 1.8
  • maven3.0

In this paper, the construction project from the first article, the use maven way to build the project, and the use of docker-maven-plugin to build docker mirror.

Third, the renovation project, building Mirror

Transformation eureka-server project

In the pom file plus plug-in:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- tag::plugin[] -->
            <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::plugin[] -->
        </plugins>
    </build>

Spotify docker-maven-plugin the plug is constructed with a mirror docker maven plug-ins.

  • imageName specifies the name of the image, the present embodiment is forep / eureka-server
  • dockerDirectory specify the location of Dockerfile
  • refers to those needs and resources Dockerfile together, files used in constructing the mirror, into the general application of the required jar package.

Under modify configuration files:

server:
  port: 8761
eureka:
  instance:
    prefer-ip-address: true
  client:
    registerWithEureka: false
    fetchRegistry: false<br>

Write dockerfile file:

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD eureka-server-0.0.1-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 8761

docker file written instructions:

  • FROM
docker file written instructions: 
 
the FROM

FROM instruction must be specified and need instruction in Dockerfile other front, the specified underlying image may be Official remote repository can be located in the local warehouse. Subsequent instructions dependent on the instruction of the specified image. When establishing a plurality of image in the same Dockerfile may be used a plurality FROM instruction.

  • VOLUME

The format is:

VOLUME ["/data"]

That the container has a directory persistent function of storing data, the directory can be used as such a container may be shared with other containers. When the application container has a persistent data requirements can be used in the instruction Dockerfile.

  • ADD

Copy the files from the directory src to dest container. Wherein src directory path can be a relatively Dockerfile located, it may be a URL, a compressed packet may be

  • ENTRYPOINT

Commands specified to run at startup Docker containers can be set more than once, but only the last one is valid.

  • EXPOSE

Set the port number for the external Docker containers. At startup, you can use the -p option or the -P option.

Construction of Mirror

Execute the build docker image maven command:

mvn clean
mvn package docker:build

Eureka: 
  Client: 
    serviceUrl: 
      defaultzone: HTTP: // Eureka-Server: 8761 / Eureka / # this needs to be changed-Server Eureka 
Server: 
  Port: 8763 
the Spring: 
  the Application: 
    name: Service -hi

b2b2c social e-commerce platform source code, please add penguin beg: 1038774626

 

Guess you like

Origin www.cnblogs.com/itcode-code/p/10971951.html