Spring Boot 2.0 (vi): Use Docker to deploy Spring boot open source software cloud Collection

Source: Internet
Author: User
Tags mysql code docker ps docker compose

Deploy an open source project Cloud collection in just three steps to create your own personal collection system, which is simple!

The Cloud Collection project has been open source for more than 2 years, as the initial learning Spring Boot practiced hand project, using a lot of very new technology, now it seems that many new technologies are not necessary to use, but as a learning case is really a good Spring boot practice.

From open source to now, I have written some tutorials to show you how to deploy a cloud collection, how to run the Cloud collection in the IDE, but still have a lot of friends do not know how to use, how to deploy? Just like "Please provide a cloud collection data structure" I have answered at least 100 times and closed nearly 10 similar problems on GitHub.

This is also seen from another aspect, the deployment of the Cloud Collection project for some friends is still more complex, now with Docker we can happily solve the problem, only three steps to deploy the Cloud collection project, to create a personal collection system.

Cloud Collection

Some friends may not understand the cloud collection, to give you a brief introduction:

A cloud collection is an open source site built using Spring Boot, which allows users to bookmark a site online, anytime, anywhere, organize a collection of websites or articles on a site, and can be used as a temporary storage for later reading. As an open source software, you can allow users to import favorite content from the browser to the cloud collection, and also support the collection of cloud collection at any time to export the article to do a backup.

Products Home

Http://favorites.ren

Project Home

Https://github.com/cloudfavorites/favorites-web

Products

Core function points:

    • Collect, categorize, retrieve articles
    • Export, export (package live from the browser)
    • Can like, share, discuss
    • Registration, login, personal account
    • Temporary collection, viewing other people's collections
    • Other...

Project Use technology:

    • Vue
    • Bootstrap
    • Jquery
    • Thymeleaf
    • Spring Data Jpa
    • Spring Boot Mail
    • Webjars
    • Mysql
    • Tomcat
    • Redis

Redis post-removal is due to limited server resources and deployment headaches

Project transformation

Dependent environment

To prepare a system for more than Centos 7 server, the system needs to install Docker and Docker Compos environment, the installation method can refer to the previous two articles:

    • Docker (i): Docker Getting Started tutorial
    • Docker (iv): Docker Compose of the Three Musketeers

Docker Retrofit

The project structure after the transformation is as follows:

Because of the previous article Spring Boot 2.0 (v): Docker Compose + Spring boot + Nginx + Mysql practice has introduced this type of project structure and content meaning, so here is the main description of the new content.

docker-compose.yamlFile

Let's take a look at the docker-compose.yaml file first:

version: ‘3‘services:  nginx:   container_name: favorites-nginx   image: nginx:1.13   restart: always   ports:   - 80:80   - 443:443   volumes:     - ./nginx/conf.d:/etc/nginx/conf.d     - /tmp/logs:/var/log/nginx  mysql:   build: ./mysql   environment:     MYSQL_DATABASE: favorites     MYSQL_ROOT_PASSWORD: root     MYSQL_ROOT_HOST: ‘%‘     TZ: Asia/Shanghai   ports:   - "3306:3306"   volumes:     - ./mysql_data:/var/lib/mysql   restart: always  app:    restart: always    build: ./app    working_dir: /app    volumes:      - ./app:/app      - ~/.m2:/root/.m2      - /tmp/logs:/usr/local/logs    expose:      - "8080"    command: mvn clean spring-boot:run -Drun.profiles=docker    depends_on:      - nginx      - mysql

Relative to the previous article this time the docker-compose.yaml document has two main additions to the content:

    • 1, the Nginx and app log map to the host, convenient for us to view the log
    • 2. Mapping Mysql data storage to the host, the benefit is not to turn off the cluster after data loss

docker-compose.yamlIn the file, the log section:

version: ‘3‘services:  nginx:   volumes:     - /tmp/logs:/var/log/nginx  app:   volumes:     - /tmp/logs:/usr/local/logs

The Nginx and cloud collection project logs are mapped to the host /tmp/logs , which allows us to view the project log.

customizing MySQL initialization information

docker-compose.yamlIn the file, Mysql changes content:

version: ‘3‘services:  mysql:   build: ./mysql   environment:     TZ: Asia/Shanghai   volumes:     - ./mysql_data:/var/lib/mysql

I picked out the changes and MySQL added the TZ environment variable to point the time zone to Shanghai, and we put the MySQL image content in the MySQL directory of the project to build it separately. MySQL directory has two files, one is Dockerfile definition MySQL image, one is my.cnf file definition MySQL code and other information.

MY.CNF File Contents

#省略一部分...character_set_server=utf8character_set_filesystem=utf8collation-server=utf8_general_ciinit-connect=‘SET NAMES utf8‘init_connect=‘SET collation_connection = utf8_general_ci‘skip-character-set-client-handshake

The main purpose of this file is to let Mysql support UTF-8.

Dockerfile File Contents

FROM mysql/mysql-server:5.7COPY my.cnf /etc/my.cnf

Use the Mysql5.7 version and copy the MY.CNF from the same directory to the server /etc/my.cnf

So the information about Mysql is defined.

Other

Other content changes little, Nginx directory under the Nginx configuration file, the project added application-docker.properties files, the database connection section can be modified.

After the transformation is complete, we only need to copy the project to the deployment server and execute: docker-compose up it can be started.

Deployment

I've submitted the project's transformation to GitHub, so you can deploy your cloud collection project in just three steps.

1, download the source code decompression

Download the latest release version

wget https://github.com/cloudfavorites/favorites-web/archive/favorites-1.1.1.zip

Extract

unzip favorites-1.1.1.zip

Go to Catalog

cd favorites-web-favorites-1.1.1/

2. Modify the configuration file

Modify a fileapplication-docker.properties

vi app/src/main/resources/application-docker.properties

Modify the content as follows

Address is the address of the deployment server

3. Start the project

After the configuration is complete, the background starts

[[email protected]~]# docker-compose up -dCreating network "favoriteswebfavorites111_default" with the default driverCreating favorites-nginx                  ... doneCreating favoriteswebfavorites111_mysql_1 ... doneCreating favoriteswebfavorites111_app_1   ... done

After the boot is complete, the browser accesses the above configuration address: http://xx.xxx.xx.xx/ , you can see the homepage of the Cloud collection.

Ancillary content

To see the service running in a container after startup, you can use the following command to enter:

Use docker ps the Docker container running above the view host

[[email protected]_73_217_centos ~]# docker psCONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS                  PORTS                                      NAMESa466ce6e58a5        favoriteswebfavorites111_app     "/usr/local/bin/mv..."   16 hours ago        Up 16 hours             8080/tcp                                   favoriteswebfavorites111_app_11b4f1b912de0        nginx:1.13                       "nginx -g ‘daemon ..."   16 hours ago        Up 16 hours             0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   favorites-nginx65b481bb7741        favoriteswebfavorites111_mysql   "/entrypoint.sh my..."   16 hours ago        Up 16 hours (healthy)   0.0.0.0:3306->3306/tcp, 33060/tcp          favoriteswebfavorites111_mysql_1

Based on the Docker container ID information queried above, execute the following command

docker exec -ti CONTAINER_ID  bash#比如进入项目容器中[[email protected]_73_217_centos ~]# docker exec -ti a466ce6e58a5 bash[email protected]:/app# ps -ef|grep java...

Exit the container to execute the following command:

Then if we want to deploy the Cloud collection project is very simple, just need three steps can happily build their own collection system, the small partners hurriedly move hands.

Spring Boot 2.0 (vi): Use Docker to deploy Spring boot open source software cloud Collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.