Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Docker

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Docker is deployed. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

I: Overview

We will demonstrate deploying Spring Boot programs with Docker on CentOS 7.

We need to compile our Docker image and run the container of the image.

All major cloud computing (PAAS) platforms support publishing Docker images.

2: Dockerfile(1) Introduction

Docker uses Dokerfile files to compile its own images.

(ii) Instructions

FROM : Indicates the base image inherited by the current image

The base image is downloaded automatically when the current image is compiled

Example: FROM ubuntu

MAINTAINER : (maintainer) indicates the author of the current image

Example: MAINTAINER info

RUN : Linux commands can be executed on the current image and form a new layer

RUN /bin/bash -c "echo helloworld"

RUN ["/bin/bash", "-c", "echo hello"]

RUN is a build-time action

Example: There are two possible formats, CMD and ENTRYPOINT

CMD : (command) indicates the default behavior when starting a mirror container

A Dockerfile can only have one CMD command. The CMD command allows you to override parameters when running a mirror.

CMD is a run-time action.

Example: CMD echo "this is a test"

Can be overridden by docker run-d image_name echo "this is not a test".

EXPOSE : (expose, expose) indicates that the container must listen on the specified port at mirror runtime.

Example: EXPOSE 8080

ENV : (environment) can be used to set environment variables

Example: ENV myName=info or ENV myName info

ADD : Copy files from the current working directory to the mirror directory

Example: test. txt/mydir/ADD

ENTRYPOINT : (entrypoint) Makes the container run like an executable program, so that the mirror runtime can accept parameters for execution like software.

ENTRYPOINT is a run-time action.

Example: ENTRYPOINT ["/bin/echo"]

We can pass parameters to the mirror to run:

docker run -d image_name "this is not a test"

3: Install Docker

Install Docker with the following command:

yum install docker

Start Docker and keep it booting:

systemctl start docker #start dockersystemctl enable docker #set boot start

IV. Project Directory and Documents

New Spring Boot project, docker-demo, this project is very simple, only modified the entry class, the code is as follows:

@SpringBootApplication @RestControllerpublic class DockerDemoApplication { @RequestMapping("/") public String home() { return "Hello Docker!! "; } public static void main(String[] args) { SpringApplication.run(Ch20dockerApplication.class, args); } }

Put the jar package of dockerdemo compiled by us under the directory/var/apps/dockerdemo on CentOS 7, such as dockerdemo-0.0.1-SNAPSHOT.jar, and create a new Dokcerfile file under the directory at the same level.

The Dockerfile file contains the following contents:

FROM java:8 #Base image is Java, label (version) is 8MAINTAINER info #Author info#Add our dockerdemo-0.0.1-SNAPSHOT.jar to the image and rename it app.jarADD dockerdemo-0.0.1-SNAPSHOT.jar app.jarEXPOSE 8080 #Run mirrored container, listen on port 8080 ENTRYPOINT ["java","-jar","/app.jar"] #Run java -jar app.jar at startup

Five: Compile Mirrors

Execute the following command in/var/apps/dockerdemo directory to execute the build image:

docker build -t info/dockedemo .

Where info/dockedemo is the image name, we set info as the prefix, which is also a naming convention of Docker images.

And notice, there's one last... This is used to indicate the Dockerfile path. Dockerfile is under the current path.

At this point we look at the local mirror

docker images

VI: Operation

Run with the following command:

docker run -d --name test -p 8080:8080 info/dockerdemo

View our current container status

docker ps

The current CentOS system ip is 192.168.25.11, visit http://192.168.25.11:8080

Thank you for reading! About "Docker how to deploy" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report