The first micro service application (Eureka) released by docker under centos7

Keywords: Java Docker snapshot MySQL

1. Package under windows

Microservice applications are packaged by maven, mvn clean package is executed in pom.xml of the project, or Maven package is directly packaged by idea or eclipse

The above operation will generate the file microservice-discovery-eureka-0.0.1-SNAPSHOT.jar package in the target directory of the project

2. Copy microservice-discovery-eureka-0.0.1-SNAPSHOT.jar to the Linux environment (you can connect through CRT and other ways)

3. Create the Dockerfile file in the directory where microservice-discovery-eureka-0.0.1-SNAPSHOT.jar is located. The contents are as follows

 1 FROM java:8
 2 
 3 VOLUME /tmp
 4 
 5 ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
 6 
 7 RUN bash -c 'touch /app.jar'
 8 
 9 EXPOSE 8761
10 
11 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

4. Build a new image with the docker build command

(Note: the Dockerfile and jar package should be in the same folder)

Execute the command docker build -t cakin24/microservice-discovery-eureka-0.0.1

 1 [root@localhost microfile]# ls
 2 Dockerfile  microservice-discovery-eureka-0.0.1-SNAPSHOT.jar
 3 [root@localhost microfile]# docker build -t cakin24/microservice-discovery-eureka-0.0.1 .
 4 Sending build context to Docker daemon  44.79MB
 5 Step 1/6 : FROM java:8
 6 8: Pulling from library/java
 7 5040bd298390: Pull complete 
 8 fce5728aad85: Pull complete 
 9 76610ec20bf5: Pull complete 
10 60170fec2151: Pull complete 
11 e98f73de8f0d: Pull complete 
12 11f7af24ed9c: Pull complete 
13 49e2d6393f32: Pull complete 
14 bb9cdec9c7f3: Pull complete 
15 Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
16 Status: Downloaded newer image for java:8
17  ---> d23bdf5b1b1b
18 Step 2/6 : VOLUME /tmp
19  ---> Running in c6c8df634611
20 Removing intermediate container c6c8df634611
21  ---> 1bdb7dd203b9
22 Step 3/6 : ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
23  ---> d88f6144fb16
24 Step 4/6 : RUN bash -c 'touch /app.jar'
25  ---> Running in d217d42a3713
26 Removing intermediate container d217d42a3713
27  ---> b24c68563734
28 Step 5/6 : EXPOSE 8761
29  ---> Running in 2a2663de2b31
30 Removing intermediate container 2a2663de2b31
31  ---> 305d7a1bed02
32 Step 6/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
33  ---> Running in c7b7c777ee72
34 Removing intermediate container c7b7c777ee72
35  ---> 6e55e8eef9b1
36 Successfully built 6e55e8eef9b1
37 Successfully tagged cakin24/microservice-discovery-eureka-0.0.1:latest
38 [root@localhost microfile]# docker images
39 REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
40 cakin24/microservice-discovery-eureka-0.0.1          latest              6e55e8eef9b1        24 seconds ago      733MB
41 mysql                                                5.7                 e47e309f72c8        13 days ago         372MB
42 hello-world                                          latest              fce289e99eb9        7 weeks ago         1.84kB
43 java                                                 8                   d23bdf5b1b1b        2 years ago         643MB
44 registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql   5.7                 ec7e75e5260c        3 years ago         360MB

5. Execute the following command to run the microservice

View the image docker images. Through the above steps, you can see that there is currently another Eureka image. This is what we want

Running container: docker run -d -p 8761:8761 cakin24/microservice-discovery-eureka-0.0.1

Check the running containers. You can see that Eureka is already running

 1 [root@localhost microfile]# docker images
 2 REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
 3 cakin24/microservice-discovery-eureka-0.0.1          latest              6e55e8eef9b1        24 seconds ago      733MB
 4 mysql                                                5.7                 e47e309f72c8        13 days ago         372MB
 5 hello-world                                          latest              fce289e99eb9        7 weeks ago         1.84kB
 6 java                                                 8                   d23bdf5b1b1b        2 years ago         643MB
 7 registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql   5.7                 ec7e75e5260c        3 years ago         360MB
 8 [root@localhost microfile]# docker run -d -p 8761:8761 cakin24/microservice-discovery-eureka-0.0.1
 9 bc05ffb47756bc1193f71c668acd2ddb51392de883dba3d6f26a786723d78397
10 [root@localhost microfile]# docker ps
11 CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS              PORTS                               NAMES
12 bc05ffb47756        cakin24/microservice-discovery-eureka-0.0.1   "java -Djava.securit..."   11 seconds ago      Up 8 seconds        0.0.0.0:8761->8761/tcp              flamboyant_golick
13 e778509d7366        mysql:5.7                                     "docker-entrypoint.s..."   About an hour ago   Up About an hour    0.0.0.0:3306->3306/tcp, 33060/tcp   pwc-mysql

6. Check the operation effect

The corresponding ip and port effects for accessing the published container are as follows,

Posted by ik on Fri, 06 Dec 2019 11:26:21 -0800