Docker deploys the SpringBoot project

1. Prepare a SpringBoot project

The project is very simple, just write a random Controller that returns a string of “hello”

2. Package the project

mvn clean package

3. Package the project and upload it to the server

Create a dockerfile directory on the server

mkdir dockerfile

5. Go to the directory and create dockerFile

vi dockerfile

Create an Image

  • Write a dockerfile file
# Resources to be imported
FORM openjdk:8

# Declare who maintains it
MAINTAINER shancang

# set the LABEL
LABEL name="dockerfile-demo" version="1.0" author="shancang"

Copy the jar package to the docker root directory
COPYDemo - 0.0.1 - the SNAPSHOT. Jar dockerfile - image. The jar

Perform the startup operation
CMD ["java"."-jar"."dockerfile-image.jar"]

Copy the code
  • Build the Image file
    • docker build -t test-docker-image .

  • Execute Docker Images to see the image we built

  • Docker run -d –name test-docker-file test-docker-image
    • You can view startup logs by using docker logs test-docker-file

So far: wrap up our project deployment and run it inside Docker.

7. Upload aliyun

  • Create account
  • After you create your account, remember to set the password in the access credentials
  • Namespaces are created before push
  • The tag command is performed before push
perform
  • docker login –username=username registry.cn-hangzhou.aliyuncs.com

  • docker tag test-docker-image registry.cn-hangzhou.aliyuncs.com/username/test-docker-image

  • docker push registry.cn-hangzhou.aliyuncs.com/username/test-docker-image