编程知识 cdmana.com

Docker deploying springboot project

Experience the convenience brought by the container , I'm more curious about how to deploy my project in Docker In the mirror image of

I made a simple blog a long time ago , Then I'll build on this project now , Then my project needs mysql database

Then install one first mysql Well

pull One mysql Mirror image

$ docker pull mysql

function mysql

$ docker run -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=123456 mysql

MYSQL_ROOT_PASSWORD=123456 Set up mysql Your service password

There's a hole in this, which is , You have to enter the container interactively first , Otherwise use Navicat Unable to connect , Second, you need to turn off the firewall

$ systemctl stop firewalld
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
1080a17ee857        mysql               "docker-entrypoint.s…"   2 hours ago         Up 42 minutes      0.0.0.0:3306->3306/tcp, 33060/tcp   festive_dhawan
$ docker exec -it 1080a17ee857 /bin/bash
$ mysql -uroot -p
$ Enter password: 123456

At this time, you can use tools to connect

When the foundation is ready , You also need to build a simple image , Let's now build a simple blog Mirror image

First upload my blog.jar, Create another Dockerfile file

#  Specify base image 
FROM openjdk:8
#  Copy file 
ADD blog.jar blog.jar
ENTRYPOINT ["java", "-jar", "blog.jar"]
#  Open the specified port 
EXPOSE 8090

structure blog Mirror image

$ docker build -t blog .
 Look at the mirror image 
$ docker images
 Running the mirror 
$ docker run -p 8090:8090 -d blog

visit :http://192.168.1.102:8090/

meanwhile IDEA It also provides the function of packaging images and publishing , Let's test how it works

1、 modify Docker Of TCP Connect

$ vim /usr/lib/systemd/system/docker.service
 stay ExecStart=/usr/bin/dockerd-current  Followed by -H tcp://0.0.0.0:9190 -H unix://var/run/docker.sock
 Refresh docker To configure 
$ systemctl daemon-reload
$systemctl start docker

2、 Use IDEA Connect Docker

IDEA-->File--> Settings-->Build,Execution,Deployment-->Docker-->TCP socket-->Engune API URL:tcp://192.168.1.102:9191

If nothing else , It should be connected normally

3、 Start packaging images

Crete Deployment Configuration

Image ID or name Configuring mirrored id Or the name

Container name Give the container a name

Bind ports Binding port

Confirm to run the image , The same access :http://192.168.1.102:8090/, Either way

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Shao Jie]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/08/20210809183600791O.html

Scroll to Top