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

How to turn a jar package into a docker container

angryTom
angryTom Original
2020-03-19 13:45:36 3371browse

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

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

mkdir mydocker cd mydocker copy /xxx/app.jar ./

3. Create a new Dockerfile file

vi Dockerfile

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"]

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 .

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

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

For more related tutorials, please pay attention to thedocker tutorialcolumn 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!

Statement:
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