Package the java project into a mirror and run it in docker

1. First, prepare a maven project and make it into a jar package as shown in the figure below: Find Maven->package->After running, there is a path below.

 2, create a directory under docker

mkdir   /mydocker

3, Use Xtfp (this is a software specially used to connect to the virtual machine to upload files) to the packaged java project and pull the jar package under /mydocker 

 

 After connecting, find the jar package directly and pull it directly

4, and then create a file in the same directory

vim  Dockerfile

 5, and edit it (this file is very important!!!)

# The base image uses java

FROM  java:8

# author

MAINTAINER xiaoliu

# VOLUME specifies the temporary file directory /tmp Create a temporary file in the host /var/lib/docker directory and connect to the container's /tmp

VOLUME  /tmp

# Add the jar package to the container and rename it to ahuan_docker.jar (this is the most important!!!)

ADD  ahuan_docker-0.0.1-SNAPSHOT.jar   ahuan_docker.jar

# Run the jar package

RUN  bash  -c  'touch /ahuan_docker.jar'

ENTRYPOINT["java","-jar","/ahuan_docker.jar"]

# expose port

EXPOSE   8080

 6, and then start to make this jar package into a mirror image (note that there is a . in front of it!!!)

docker  build  -t  ahuan_docker:1.6  .

Then execute docker images to see a new image 

7, and then run the image

docker  run -d  -p  8080:8080  81ffce3265f0

Execute docker ps after running to see a new container running 

Then you can access the interface of the project on the browser, which is the IP+port number+interface path on the virtual machine

Here is a very small maven project, such as displaying helloworld on the page, without connecting to mysql, and not connecting to redis... It just records how to make the jar package into a mirror image and simply run it!

Guess you like

Origin blog.csdn.net/liujiahuan_/article/details/126186347