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 install Docker and deploy the Spring Boot project

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

Share

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

This article mainly introduces "how to install Docker and deploy Spring Boot project". In daily operation, I believe many people have doubts about how to install Docker and deploy Spring Boot project. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to install Docker and deploy Spring Boot project". Next, please follow the editor to study!

prerequisite

A CentOS7 server. I am using Aliyun's server here, and I choose the CentOS7 version system.

Use a remote connection tool like xshell6 to connect to the server. Reference article: using xshell6 to remotely connect to a Linux server

If you need a domain name to access a project deployed by Docker, you need to have a domain name first. The domain name I used in my demonstration here is applied for in Aliyun. For more information, see Aliyun Domain name Registration.

Installation command

It is recommended that the installation of Docker,window environment under linux environment is complex and error-prone, so it is convenient to use Centos7+yum to install Docker environment.

The Docker package is already included in the default CentOS-Extras software source. So to install docker, simply run the following yum command:

Yum install docker

Start the Docker service

After the installation is complete, use the following command to start the docker service and set it to boot:

Service docker startchkconfig docker on

Test Docker installation successfully

test

Docker version

Enter the above command and return the information about the version of docker, which proves that docker is installed successfully.

Set up a domestic image

Modify docker to domestic image address: https://registry.docker-cn.com via vim

Because the official warehouse connected to Docker in China is very slow, we use Docker China Accelerator in our daily use. Through the acceleration of Docker official images, users in China can quickly access the most popular Docker images. The image is hosted on Chinese mainland, and local users will now enjoy faster download speeds and greater stability, allowing them to develop and deliver Docker-based applications more agile.

Docker China's official image acceleration can be accessed through registry.docker-cn.com. The mirror library contains only popular public images, and private images still need to be pulled from the US mirror library.

Just modify the configuration file corresponding to docker in the system, as follows:

After vi / etc/docker/daemon.json# is added, {"registry-mirrors": ["https://registry.docker-cn.com"]," live-restore ": true}

Demonstrate the Hello World program / / run the following command to grab the image file from the repository to the local. In the code above in docker pull library/hello-world//, docker image pull is the command to grab the image file. / / library/hello-world is the location of the image file in the repository, / / where library is the group where the image file is located, and hello-world is the name of the image file. Docker images// now, run the image file. Docker run hello-world

After you print this prompt, the hello world stops running and the container terminates automatically. Some containers do not terminate automatically because they provide services, such as Mysql images.

Install Docker Compose

With Docker-Compose, users can easily define a multi-container application with a configuration file, and then install all the dependencies of the application using one instruction to complete the build. Docker-Compose solves the problem of how to manage orchestration between containers. Dockerfile allows users to manage a separate application container, while Compose allows users to define a set of associated application containers (called a project, that is, a project) in a template (YAML format), such as a Web service container plus a back-end database service container.

Docker Compose is a stand-alone product of Docker, so you need to install Docker Compose. Docker Compose after installing Docker.

# download sudo curl-L https://github.com/docker/compose/releases/download/1.20.0/docker-compose-`uname-s`-`uname-m`-o / usr/local/bin/docker-compose# install chmod + x / usr/local/bin/docker-compose# to view the version docker-compose version

Common command

In addition to the Docker command we used above, Docker has some other commonly used commands

Pull docker image

Docker pull image_name

View the image on the host. The Docker image is stored in the / var/lib/docker directory:

Docker images

Delete Mirror

Docker rmi docker.io/tomcat:7.0.77-jre7 or docker rmi b39c68b7af30

See which containers are currently running

Docker ps

View all containers

Docker ps-a

Start, stop, restart container commands:

Docker start container_name/container_iddocker stop container_name/container_iddocker restart container_name/container_id

After launching a container in the background, if you want to enter the container, you can use the attach command:

Docker attach container_name/container_id

Command to delete a container:

Docker rm container_name/container_id

Delete all stopped containers:

Docker rm $(docker ps-a-Q)

View current system Docker information

Docker info

Download an image from Docker hub:

Docker pull centos:latestdocker pull centos:latest

Find the nginx image on Docker Hub

Docker search nginx

Executing docker pull centos will download all the images under the Centos repository to the local repository.

Deployment project demo (cloud collection)

Deploy SpringBoot project-Cloud Collection

Address: https://github.com/cloudfavorites/favorites-web

-bash: unzip: no command was found, just execute the following command. It is also suitable for Unix kernel system.

Yum install-y unzip zip

Drop-down items:

Wget https://github.com/cloudfavorites/favorites-web/archive/favorites-1.3.0.zip

Decompression

Unzip favorites-1.3.0.zip

Enter the directory

Cd favorites-web-favorites-1.3.0/ modifies the file application-docker.propertiesvi app/src/main/resources/application-docker.properties

The modifications are as follows

Favorites.base.path= http://xx.xxx.xx.xx/ forgotpassword.url= http://xx.xxx.xx.xx/newPassword-the address of the deployment server deployment command: ```javadocker-compose up-- build or docker-compose up-d org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed Nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'forgotpassword.url' in value "${forgotpassword.url}" app_1 | at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues (AutowiredAnnotationBeanPostProcessor.java:379) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean (AbstractAutowireCapableBeanFactory.java:1344) ~ [spring-beans-5.0.4. RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:582) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:502) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:312) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:228) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory. DoGetBean (AbstractBeanFactory.java:310) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:200) ~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.

Modify the project configuration file:

Favorites.base.path=http:// public network ip/forgotpassword.url=http:// public network ip/newPassword

The project was launched successfully:

Visit ip: http://47.100.188.105/ to view the project home page

At this point, the study on "how to install Docker and deploy the Spring Boot project" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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