Home > Operation and Maintenance > Docker > How to turn a jar package into a docker container

How to turn a jar package into a docker container

angryTom
Release: 2020-03-19 13:46:19
Original
3510 people have browsed it

How to turn a jar package into a docker container

How to turn a jar package into a docker container

1. First download the java image

docker pull java:8
Copy after login

2. Create a new working directory and copy the jar package into it

mkdir mydocker
cd mydocker
copy /xxx/app.jar ./
Copy after login

3. Create a new Dockerfile file

vi Dockerfile
Copy after login

The content of the file is as follows:

(Recommended learning: jquery video tutorial)

FROM java:8
MAINTAINER freebytes.net
WORKDIR  /test
COPY app.jar /test/app.jar
CMD ["java","-jar","app.jar","-Dfile.encoding=utf-8"]
Copy after login

Code explanation

FROM java:8 ——Indicates that it is built based on the java:8 mirror

MAINTAINER author——Indicates that the build author is author

WORKDIR /test——Indicates that the working directory in the specified container is/test

COPY——Copy app.jar to the container Working directory/test

CMD - Execute the java instruction to start the jar.

4. Build the image

docker build -t app-docker .
Copy after login

means building the image from the current directory. This command will package all the files in the current directory and send them to the docker engine server. , and then perform build operations based on the Dockerfile on the server side.

5. After the build is successful, start the container

docker run -it -p 9013:8088 –name app -d my-docker
Copy after login

According to the Dockerfile configuration just now, after the container is generated, the test directory will inevitably be generated in the container root directory, and test There is an app.jar file in the directory, and the instructions defined by the CMD executed by the container are also based on the test directory.

You can enter the container to view

docker exec -it app /bin/bash
Copy after login

For more related tutorials, please pay attention to the docker tutorial column on the PHP Chinese website.

The above is the detailed content of How to turn a jar package into a docker container. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template