ํฐ์คํ ๋ฆฌ ๋ทฐ
์์ ํ๊ฒฝ
window10
wsl2-ubuntu
์ฐ์ ๋์ปค๋ฅผ ํ์ฉํด ํฐ์ผ ์ปจํ ์ด๋๋ฅผ ๊ตฌ์ฑํด๋ด ๋๋ค.
๋ค์ ๋งํฌ์์ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ ์ฐธ๊ณ ํด ์ฃผ์ธ์!
[ Docker ] ๋์ปค๋ก ํฐ์ผ(์ปจํ ์ด๋) ์คํํ๊ธฐ
๋์ปค์ ๊ธฐ๋ณธ์ ์ธ ํ๊ฒฝ ๊ตฌ์ฑ์ ๋์ด ์๋ค ๊ฐ์ ํฉ๋๋ค. ์์ฑ์ ํ๊ฒฝ๊ตฌ์ฑ win10 wsl2 - ubuntu 1. ๋์ปค๋ก ํฐ์ผ ์ด๋ฏธ์ง ์ฐพ๊ธฐ ํฐ์ผ์ ๊ตฌ์ฑํ๊ธฐ ์ํด ์ฐ๋ฆฌ๋ ํฐ์ผ ์ด๋ฏธ์ง๋ฅผ ๋ด๋ ค๋ฐ์์ผ ํฉ๋๋ค. ๊ทธ์ ์ ๋์ปค
kithub.tistory.com
1. ์ํ ํ๋ก์ ํธ ์์ฑ
์ ๋ war ๋ฐฐํฌ๋ฅผ ์ํด ๋ค์๊ณผ ๊ฐ์ด ํ๋ก์ ํธ๋ฅผ ๊ตฌ์ฑํด ๋ณด์์ต๋๋ค.
๊ตฌ์ฑ ํ๊ฒฝ
springboot 3.0.2
jdk 17
STS
์์กด์ฑ
Spring boot DevTools
Spring web
ํ๋ก์ ํธ๊ฐ ์์ฑ๋์๋ค๋ฉด
์ด์ index.html์ ์์ฑํด์ ๊ฐ๋จํ ํ ์คํธ ํ์ด์ง๋ฅผ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
index.html
- /src/main/resources/static/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>kithub</title>
</head>
<body>
<h2>์๋
ํ์ธ์ ๋ฐ๊ฐ์ต๋๋ค. kithub ์
๋๋ค.^^</h2>
</body>
</html>
html ์์ฑ ํ ํฐ์ผ์ ์คํ์์ผ ๋ณด๋ฉด ํ ์คํธ ํ์ด์ง๊ฐ ์ ์์ ์ผ๋ก ๊ตฌ๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
2. ๋ฐฐํฌ ํ์ผ ๋ง๋ค๊ธฐ
๊ฐ๋จํ ์น ํ๋ก์ ํธ๋ฅผ ๊ตฌํํ์ผ๋ ์ด์ ์ฐ๋ฆฌ๋ ํฐ์ผ์ ๋ฐฐํฌํ WAR ํ์ผ์ ๋ง๋ค์ด๋ณผ ์ฐจ๋ก์ ๋๋ค.
์ฐ์ springboot๋ก war ํ์ผ์ ๋ง๋ค๊ธฐ ์ ์ ์ฌ์ ์์ ์ด ํ์ํฉ๋๋ค.
pom.xml ํ์ผ์ ์ด๊ณ ๋ค์ ๊ตฌ์ฑ์ผ๋ก ๋ณ๊ฒฝํด ์ค์๋ค.
<properties></proerties>์ ๊ตฌ์ฑ์ ์๋์ ๊ฐ์ด ์ปดํ์ผ๋ฌ๋ฅผ ์ถ๊ฐํด ์ค๋๋ค.
<properties>
<java.version>17</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
๊ทธ๋ฆฌ๊ณ ,
<build></build> ์ ๊ตฌ์ฑ๋ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํด ์ค๋๋ค.
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
์ด์ ๋ฐฐํฌํ์ผ ์์ฑ์ ์ํ ์์ ์ ๋์ด ๋ฌ์ต๋๋ค.
pom.xml ์ ์ฒด ์์ค
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.kithub.docker</groupId>
<artifactId>docker-1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>17</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<name>docker-1</name>
<description>Demo project for Spring Boot</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
์ด์ war ํ์ผ์ ์์ฑํด ๋ด ๋๋ค.
ํ๋ก์ ํธ ์ฐํด๋ฆญ > export > web > WAR file ์ ์ ํํฉ๋๋ค.
next๋ฅผ ๋๋ฅธ ๋ค ๋ฐฐํฌํ์ผ์ ์ ์ฅํ ๊ฒฝ๋ก๋ฅผ ์ง์ ํด ์ค์๋ค.
์์ฑ์ด ๋๋๋ฉด ์ง์ ํ ์์น์์ war ํ์ผ์ด ์ ๋๋ก ์์ฑ๋์ด ์๋์ง ํ์ธํด ๋ด ๋๋ค.
3. ํฐ์ผ ์ปจํ ์ด๋์ war ๋ฐฐํฌํ๊ธฐ
์ด์ ๋ฐฐํฌ๋ฅผ ์ํ ๋ชจ๋ ์ค๋น๋ฅผ ๋ง์ณค์ต๋๋ค.
์ด์ ํด์ผ ํ ์ผ์ ์ฐ๋ฆฌ๊ฐ ๋ง๋ war ํ์ผ์ ๋์ปค๋ก ์ฌ๋ ค๋์ ํฐ์ผ(์ปจํ ์ด๋) ํด๋๋ก ์ฎ๊ธฐ๋ ์์ ์ ํด์ผ ํฉ๋๋ค.
> wsl2(์ฐ๋ถํฌ)์์ ์๋์ฐ ์์คํ
์ ๊ทผํ๊ธฐ
์ฐ์ /mnt ํด๋๋ก ์ฐพ์ ๋ค์ด๊ฐ ๋ค ๋ชฉ๋ก์ ํ์ํด ๋ณด๋ฉด c d wsl ์ด ์กด์ฌํ๊ณ ์์์ ์ ์ ์์ต๋๋ค. ์ด๋ wsl๊ณผ ์๋์ฐ์ ๋๋ผ์ด๋ธ๋ ์๋ก ๋ง์ดํธ ๋์ด ์์ต๋๋ค. ๋ณ๋์ ftp ํ๋ก๊ทธ๋จ ์์ด ๋ฆฌ๋
์ค์ ์๋์ฐ๊ฐ์ ํ์ผ ์ด๋/๋ณต์ฌ๊ฐ ์์ฝ๊ฒ ๊ฐ๋ฅํฉ๋๋ค.
sintae@DESKTOP-JAQ684D:/$ cd /mnt
sintae@DESKTOP-JAQ684D:/mnt$ ls
c d wsl
์๋์ฐ ๋๋ผ์ด๋ธ์ ์ ๊ทผํ์ผ๋ ์์์ ์์ฑํ war ํ์ผ์ ์ฎ๊ฒจ๋ณด๋๋ก ํด๋ณด๊ฒ ์ต๋๋ค.
> ํ์ผ ๋ณต์ฌํ๊ธฐ
์ฐ๋ฆฌ๋ cp ๋ช ๋ น์ด๋ฅผ ์ด์ฉํด war ํ์ผ์ ํฐ์ผ(์ปจํ ์ด๋)๋ก ๋ณต์ฌํด๋ณด๊ฒ ์ต๋๋ค.
docker cp [๋ณต์ฌํ ํ์ผ๋ช ] [์ปจํ ์ด๋ID]:[๋ณต์ฌํ ๊ฒฝ๋ก]
docker cp ๋ช ๋ น์ด ๊ณต์๋ฌธ์
sintae@DESKTOP-JAQ684D:/mnt/c/coding$ docker cp docker.war 76be015094f2:/usr/local/tomcat/webapps/
76be015094f2 ID๋ก ์คํ์ค์ธ ์ปจํ ์ด๋์ /usr/local/tomcat/webapps/ ๊ฒฝ๋ก๋ก docker.war ํ์ผ์ ๋ณต์ฌํด์ค
๋ผ๋ ์๋ฏธ ์ ๋๋ค.
๊ทธ๋ผ ์ค์ ๋ก ๋ณต์ฌ๊ฐ ๋์๋์ง ํ์ธํด๋ณด๊ฒ ์ต๋๋ค.
sintae@DESKTOP-JAQ684D:/mnt/c/coding$ docker exec -it 76be015094f2 /bin/bash
root@76be015094f2:/usr/local/tomcat# cd webapps
root@76be015094f2:/usr/local/tomcat/webapps# ll
total 14820
drwxr-xr-x 8 root root 4096 Feb 11 09:20 ./
drwxr-xr-x 1 root root 4096 Feb 11 07:41 ../
drwxr-x--- 4 root root 4096 Feb 11 09:20 docker/
-rwxrwxrwx 1 1000 1000 15138743 Feb 11 07:30 docker.war*
drwxr-xr-x 15 root root 4096 Feb 1 02:40 docs/
drwxr-xr-x 7 root root 4096 Feb 1 02:40 examples/
drwxr-xr-x 6 root root 4096 Feb 1 02:40 host-manager/
drwxr-xr-x 6 root root 4096 Feb 1 02:40 manager/
drwxr-xr-x 3 root root 4096 Feb 1 02:40 ROOT/
์คํ์ค์ธ ํฐ์ผ ํด๋์ ์ ๊ทผํ์ฌ ๋ชฉ๋ก์ ์ดํด๋ณด๋ฉด ์ค์ ๋ก 'docker.war*' ๋ผ๋ ํ์ผ์ด ๋ณต์ฌ๋ ์๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
docker/ ํด๋๊ฐ ์์ฑ ๋์ด ์๋ ์ด์ ๋ webapps ํด๋์ war๋ฅผ ๊ฐ์งํ๊ธฐ ๋๋ฌธ์ ๋๋ค.
์, ๋๋์ด ์ฐ๋ฆฐ ๋์ปค๋ก ๊ตฌ์ฑํ ํฐ์ผ์ war ํ์ผ์ ์ฎ๊ธฐ๋๋ฐ ์ฑ๊ณตํ์ต๋๋ค.
์ด์ ์ฐ๋ฆฌ์ ํฐ์ผ์ด ์ค์ค๋ก war๋ฅผ ๋ฐฐํฌํด ์ฃผ์์ผ๋, ์ ์์ ํด๋ณด๋๋ก ํฉ๋๋ค.
http://localhost:8085/docker/ ์ ์!
๊น๋ํ๊ฒ ์๋ฌด๋ฌธ์ ์์ด ์ ๋๋ก ๋ฐฐํฌ๊ฐ ๋์์์ ํ์ธํ์์ต๋๋ค !
'โ Tools > โ Docker' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ Docker ] ๋์ปค๋ก ํฐ์ผ(์ปจํ ์ด๋) ์คํํ๊ธฐ (3) | 2023.02.05 |
---|