Commit 41d4d0b9 authored by insun park's avatar insun park
Browse files

docker/README.md 및 docker 하위 프로젝트 일괄 추가

parent c384e1fe
#!/usr/bin/perl -w
# Copyright (C) 1997-2018 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1997.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
$PACKAGE = "libc";
$progname = $0;
if ($ENV{CC}) {
$CC = $ENV{CC};
} else {
$CC= "gcc";
}
if ($ENV{LD_SO}) {
$LD_SO = $ENV{LD_SO};
} else {
$LD_SO = "";
}
sub usage {
print "Usage: test-installation [soversions.mk]\n";
print " --help print this help, then exit\n";
print " --version print version number, then exit\n";
exit 0;
}
sub installation_problem {
print "The script has found some problems with your installation!\n";
print "Please read the FAQ and the README file and check the following:\n";
print "- Did you change the gcc specs file (necessary after upgrading from\n";
print " Linux libc5)?\n";
print "- Are there any symbolic links of the form libXXX.so to old libraries?\n";
print " Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,\n";
print " libm.so should point to the newly installed glibc file - and there should be\n";
print " only one such link (check e.g. /lib and /usr/lib)\n";
print "You should restart this script from your build directory after you've\n";
print "fixed all problems!\n";
print "Btw. the script doesn't work if you're installing GNU libc not as your\n";
print "primary library!\n";
exit 1;
}
arglist: while (@ARGV) {
if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
$ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
$ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
print "test-installation (GNU $PACKAGE)\n";
print "Copyright (C) 2018 Free Software Foundation, Inc.\n";
print "This is free software; see the source for copying conditions. There is NO\n";
print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
print "Written by Andreas Jaeger <aj\@arthur.rhein-neckar.de>\n";
exit 0;
} elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
$ARGV[0] eq "--help") {
&usage;
} elsif ($ARGV[0] =~ /^-/) {
print "$progname: unrecognized option `$ARGV[0]'\n";
print "Try `$progname --help' for more information.\n";
exit 1;
} else {
last arglist;
}
}
# We expect none or one argument.
if ($#ARGV == -1) {
$dir = ".";
$soversions="soversions.mk";
$config="config.make";
} elsif ($#ARGV == 0) {
if (-d $ARGV[0]) {
$dir = $ARGV[0];
$soversions = "$ARGV[0]/soversions.mk";
$config = "$ARGV[0]/config.make";
} else {
$soversions = $dir = $ARGV[0];
$dir =~ s!/?[^/]*/*$!!;
$config = $dir . "/config.make";
}
} else {
die "Wrong number of arguments.";
}
if (system ("grep -q \"build-mathvec = yes\" $config") == 0) {
$build_mathvec = 1;
} else {
$build_mathvec = 0;
}
# Read names and versions of all shared libraries that are part of
# glibc
open SOVERSIONS, $soversions
or die ("Couldn't open $soversions in build directory!");
$link_libs = "";
%versions = ();
while (<SOVERSIONS>) {
next if (/^all-sonames/);
chop;
if (/^lib/) {
($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
# Filter out some libraries we don't want to link:
# - nss_ldap since it's not yet available
# - libdb1 since it conflicts with libdb
# - libthread_db since it contains unresolved references
# - it's just a test NSS module
# - We don't provide the libgcc so we don't test it
# - libmvec if it wasn't built
next if ($build_mathvec == 0 && $name eq "mvec");
if ($name ne "nss_ldap" && $name ne "db1"
&& $name ne "thread_db"
&& $name ne "nss_test1" && $name ne "nss_test2" && $name ne "libgcc_s") {
$link_libs .= " -l$name";
$versions{$name} = $version;
}
} elsif ($LD_SO ne "") {
($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO);
} else {
if (/^ld\.so/) {
($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
}
}
}
close SOVERSIONS;
# Create test program and link it against all
# shared libraries
open PRG, ">$dir/test-prg$$.c"
or die ("Couldn't write test file $dir/test-prg$$.c");
print PRG '
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf ("Your new glibc installation seems to be ok.\n");
exit (0);
}
';
close PRG;
open GCC, "$CC $dir/test-prg$$.c $link_libs -o $dir/test-prg$$ 2>&1 |"
or die ("Couldn't execute $CC!");
while (<GCC>) {
print $_ if (! /warning/);
}
close GCC;
if ($?) {
print "Execution of $CC failed!\n";
&installation_problem;
}
# Test if test program is linked against the right versions of
# shared libraries
$ok = 1;
%found = ();
open LDD, "ldd $dir/test-prg$$ |"
or die ("Couldn't execute ldd");
while (<LDD>) {
if (/^\s*lib/) {
($name, $version1, $version2) =
/^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
$found{$name} = 1;
if ($versions{$name} ne $version1 || $version1 ne $version2) {
print "Library lib$name is not correctly installed.\n";
print "Please check your installation!\n";
print "Offending line of ldd output: $_\n";
$ok = 0;
}
}
if (/$ld_so_name/) {
($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
if ($version1 ne $ld_so_version) {
print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
print "Please check your installation!\n";
print "Offending line of ldd output: $_\n";
$ok = 0;
}
}
}
close LDD;
die "ldd execution failed" if $?;
foreach (keys %versions) {
unless ($found{$_}) {
print "Library lib$_ is not correctly installed since the test program\n";
print "was not linked dynamically against it.\n";
print "Do you have a file/link lib$_.so?\n";
$ok = 0;
}
}
&installation_problem unless $ok;
# Finally execute the test program
system ("$dir/test-prg$$") == 0
or die ("Execution of test program failed");
# Clean up after ourselves
unlink ("$dir/test-prg$$", "$dir/test-prg$$.c");
# Dockerfile
FROM python:3.10-slim-buster
WORKDIR /app
COPY ../../geumdo_analysis ./
RUN pip install --no-cache-dir -r requirements.txt; \
apt-get update; \
apt-get install -y --no-install-recommends \
git \
curl \
vim \
; \
apt-get remove -y --auto-remove \
wget \
; \
rm -rf /var/lib/apt/lists/*;
CMD unicorn --host=0.0.0.0 --port 8000 main:app
# 크롤링/분석 FastAPI 서버
이 프로젝트는 프로젝트 루트(`../../`)에 위치한 `geumdo_analysis` 디렉토리의 Python 애플리케이션을 FastAPI 서버로 실행하기 위한 Docker 환경입니다.
**경고: 이 Docker 설정은 외부 디렉토리에 강하게 의존하고 있으며, 빌드와 실행 방식에 혼동의 여지가 있습니다. 아래 설명을 주의 깊게 읽어주세요.**
## 프로젝트 구조 및 의존성
- **소스 코드 위치**: 이 Docker 컨테이너는 `docker/docker_crowling` 폴더의 상위 폴더인 프로젝트 루트에 있는 `geumdo_analysis` 라는 디렉토리의 소스 코드를 실행하도록 설계되었습니다.
- **애플리케이션 타입**: `unicorn`을 사용하는 것으로 보아, `geumdo_analysis`는 FastAPI 또는 Starlette 기반의 ASGI 웹 애플리케이션일 가능성이 높습니다.
- **Dockerfile 동작**: 빌드 시 `geumdo_analysis` 폴더의 내용을 이미지 안으로 복사(`COPY`)합니다.
- **docker-compose 동작**: 컨테이너 실행 시, `fastapi_app` 이라는 외부 Docker 볼륨을 컨테이너의 `/app` 디렉토리에 마운트합니다. **이 과정에서 Dockerfile에 의해 복사된 소스 코드는 볼륨에 의해 덮어씌워져 무시됩니다.**
결론적으로, 이 컨테이너가 정상적으로 동작하려면 **`fastapi_app` 볼륨 내부에 `geumdo_analysis`의 소스 코드가 사전에 존재해야 합니다.**
## 사전 요구사항
- [Docker](https://www.docker.com/get-started)
- [Docker Compose](https://docs.docker.com/compose/install/)
- 프로젝트 루트에 `geumdo_analysis` 소스 코드 폴더가 존재해야 합니다.
- `geumdo_analysis` 폴더 내에 `requirements.txt``main.py` 파일(`app` 객체 포함)이 있어야 합니다.
## 사용 방법
### 1. (최초 설정) 소스 코드를 볼륨에 복사
`rebuild.sh`는 빈 볼륨만 생성해주므로, 사용자가 직접 소스 코드를 볼륨으로 옮겨야 합니다.
```bash
# 1. 빌드 스크립트를 실행하여 빈 볼륨과 이미지를 생성하고, 임시 컨테이너를 실행
./rebuild.sh
# 2. 프로젝트 루트의 geumdo_analysis 폴더 전체를 fastapi_server 컨테이너의 /app 디렉토리로 복사
# (컨테이너의 /app 디렉토리는 fastapi_app 볼륨과 연결되어 있음)
docker cp ../../geumdo_analysis/. fastapi_server:/app/
# 3. 임시 컨테이너 재시작하여 코드 변경사항 반영
docker-compose restart
```
### 2. (이후) 서비스 시작
이미 볼륨에 소스 코드가 준비된 상태라면, 아래 명령어로 서비스를 시작할 수 있습니다.
```bash
docker-compose up -d
```
## 서비스 접속 정보
- **서비스 포트**: 호스트의 `8100`번 포트가 컨테이너의 `8000`번 포트로 매핑됩니다.
- **API 주소**: `http://<서버_IP>:8100`
\ No newline at end of file
version: '3'
services:
fastapi_server:
build:
context: .
dockerfile: .
ports:
- "8100:8000"
network_mode: bridge
volumes:
- fastapi_app:/app
volumes:
fastapi_app:
external: true
#!/bin/sh
create_volume() {
docker volume inspect $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Volume '$1' already exists."
else
docker volume create --name=$1
echo "Volume '$1' created."
fi
}
create_volume fastapi_app
docker build -t fastapi .
docker-compose up -d
# images
FROM ubuntu:20.04
# package procedure(update&upgrade&install)
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y openssh-server && \
apt-get install -y vim net-tools && \
apt-get install -y apt-utils && \
apt-get install -y iputils-ping && \
apt-get install -y wget && \
apt-get install -y tar && \
apt-get install -y curl && \
apt-get install -y language-pack-ko && \
apt-get install -y mariadb-server mariadb-client && \
apt-get install -y telnet
#package clean unused
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config
# SSH login fix. Otherwise, user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
# mariadb install and setting
RUN sed -ri 's/^#?bind-address\s+.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN sed -ri 's/^#?max_allowed_packet\s+.*/max_allowed_packet = 16M/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo lower_case_table_names=1 >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo default-time-zone='+9:00' >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo skip-character-set-client-handshake >> /etc/mysql/mariadb.conf.d/50-server.cnf
COPY make_root_remote_host.sh .
RUN chmod +x ./make_root_remote_host.sh
COPY setting.sql .
# Expose port
EXPOSE 22 3306 9011 9013
# Run ssh,db
ENTRYPOINT ["/bin/bash", "-c", "\
source /etc/profile && \
service mysql start && \
service ssh start && \
sh ./make_root_remote_host.sh && \
tail -f /dev/null"]
# MariaDB 서버 (자동 원격 설정)
이 프로젝트는 Ubuntu 20.04 기반의 MariaDB 서버 환경을 Docker를 사용하여 구축합니다. 컨테이너가 시작될 때 ** 자동으로 원격 접속이 가능한 `root` 계정을 설정**하여 사용자의 편의성을 높인 것이 특징입니다. SSH 접속 또한 가능합니다.
## 주요 기능
- **기반 환경**: Ubuntu 20.04
- **데이터베이스**: MariaDB Server
- **원격 접속**: OpenSSH Server
- **자동 설정**: 컨테이너 시작 시, 모든 IP에서 접근 가능한 `root` 계정을 생성하고 비밀번호를 설정하는 스크립트가 자동으로 실행됩니다.
## 사전 요구사항
- [Docker](https://www.docker.com/get-started)
- [Docker Compose](https://docs.docker.com/compose/install/)
## 사용 방법
프로젝트 루트 디렉토리에서 아래 쉘 스크립트를 실행하기만 하면 됩니다.
```bash
./rebuild.sh
```
이 스크립트는 다음 작업을 자동으로 수행합니다:
1. MariaDB 데이터(`dbkeydata`)와 홈 디렉토리(`dbhome`)를 영속적으로 저장하기 위한 Docker 볼륨을 확인하고 없는 경우 생성합니다.
2. `Dockerfile`을 기반으로 이미지를 빌드합니다.
3. `docker-compose.yml` 설정을 사용하여 서비스를 시작합니다.
4. 컨테이너 내부적으로 원격 접속 설정을 완료합니다.
별도의 수동 설정 과정 없이 바로 데이터베이스에 원격으로 접속할 수 있습니다.
## 서비스 접속 정보
| 서비스 | 호스트 포트 | 컨테이너 포트 | 주소 / 명령어 | 계정 | 비밀번호 |
|---|---|---|---|---|---|
| SSH | `2228` | `22` | `ssh root@<서버_IP> -p 2228` | `root` | `!@#gds$%^` |
| MariaDB | `33062`| `3306` | `<서버_IP>` | `root` | `!@#gds$%^` |
| 기타 | `9011`| `9011` | (용도 확인 필요) | - | - |
| 기타 | `9013`| `9013` | (용도 확인 필요) | - | - |
## 데이터 영속성 (볼륨)
- `dbkeydata`: MariaDB의 데이터 파일(`_path`)이 저장됩니다.
- `dbhome`: 컨테이너의 `/home` 디렉토리와 연결됩니다.
\ No newline at end of file
version: '3'
services:
server:
build:
context: .
dockerfile: Dockerfile
ports:
- "2228:22"
- "33062:3306"
- "9011:9011"
- "9013:9013"
network_mode: bridge
restart: always
volumes:
- dbkeydata:/var/lib/mysql
- dbhome:/home
volumes:
dbkeydata:
external: true
dbhome:
external: true
#!/bin/sh
mysql -u root -p!@#gds$%^ < setting.sql;
#!/bin/sh
create_volume() {
docker volume inspect $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Volume '$1' already exists."
else
docker volume create --name=$1
echo "Volume '$1' created."
fi
}
create_volume dbkeydata
create_volume dbhome
docker build -t docker_db
docker-compose up -d --build
#원하는 루트 원격 계정 password 입력
grant all privileges on *.* to root@'%' identified by '!@#gds$%^';
flush privileges;
# images
FROM ubuntu:20.04
# package procedure(update&upgrade&install)
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y openssh-server && \
apt-get install -y vim net-tools && \
apt-get install -y apt-utils && \
apt-get install -y iputils-ping && \
apt-get install -y wget && \
apt-get install -y tar && \
apt-get install -y curl && \
apt-get install -y language-pack-ko && \
apt-get install -y mariadb-server mariadb-client
#package clean unused
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise, user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
# mariadb install and setting
RUN sed -ri 's/^#?bind-address\s+.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN sed -ri 's/^#?max_allowed_packet\s+.*/max_allowed_packet = 16M/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo lower_case_table_names=1 >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo default-time-zone='+9:00' >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo skip-character-set-client-handshake >> /etc/mysql/mariadb.conf.d/50-server.cnf
COPY make_root_remote_host.sh .
COPY setting.sql .
# Expose port
EXPOSE 22 3306
CMD ["root_remote_host.sh"]
# Run ssh,db
ENTRYPOINT ["/bin/bash", "-c", "\
source ~/.bashrc && \
service mysql start && \
service ssh start && \
tail -f /dev/null"]
# MariaDB Docker 환경
이 프로젝트는 Ubuntu 20.04 기반의 MariaDB 서버 환경을 Docker를 사용하여 구축합니다. SSH 접속 또한 가능합니다.
## 주요 기능
- **베이스 이미지**: Ubuntu 20.04
- **데이터베이스**: MariaDB Server
- **원격 접속**: OpenSSH Server
## 사전 요구사항
- [Docker](https://www.docker.com/get-started)
- [Docker Compose](https://docs.docker.com/compose/install/)
## 사용 방법
### 1. 서비스 시작 및 빌드
프로젝트 루트 디렉토리에서 아래 쉘 스크립트를 실행합니다.
```bash
./rebuild.sh
```
이 스크립트는 다음 작업을 자동으로 수행합니다:
1. MariaDB 데이터를 영속적으로 저장하기 위한 Docker 볼륨(`dbdata`)을 확인하고 없는 경우 생성합니다.
2. `Dockerfile`을 기반으로 이미지를 빌드합니다.
3. `docker-compose.yml` 설정을 사용하여 서비스를 시작합니다.
### 2. MariaDB 원격 접속 계정 설정 (수동)
컨테이너가 실행된 후, 원격에서 MariaDB에 접속하려면 아래의 추가 설정이 필요합니다.
먼저, 실행중인 컨테이너의 이름이나 ID를 확인합니다.
```bash
docker ps
```
그런 다음, 아래 명령어를 실행하여 컨테이너 내부의 설정 스크립트를 실행합니다.
```bash
# `docker_db_new_server_1`은 예시 컨테이너 이름입니다. `docker ps` 명령어로 확인한 실제 컨테이너 이름으로 바꿔주세요.
docker exec -it docker_db_new_server_1 /bin/bash -c "./make_root_remote_host.sh"
```
이 스크립트는 `root` 계정이 모든 외부 IP(`%`)에서 접속할 수 있도록 권한을 부여하고 비밀번호를 설정합니다.
## 서비스 접속 정보
| 서비스 | 호스트 포트 | 컨테이너 포트 | 주소 / 명령어 | 계정 | 비밀번호 |
|---|---|---|---|---|---|
| SSH | `2113` | `22` | `ssh root@<서버_IP> -p 2113` | `root` | `!@#gds$%^` |
| MariaDB | `33066`| `3306` | `<서버_IP>` | `root` | `!@#gds$%^` |
**참고:** MariaDB의 `root` 계정은 컨테이너 최초 실행 시 비밀번호가 설정되어 있지 않습니다. 원격 접속 설정을 완료해야 위 테이블의 비밀번호로 접속 가능합니다.
## 데이터 영속성
- **볼륨**:
- `dbdata`: MariaDB의 데이터 파일(`_path`)이 저장됩니다. 이 볼륨이 존재하면 컨테이너를 삭제하고 재생성해도 데이터가 보존됩니다.
\ No newline at end of file
version: '3'
services:
server:
build:
context: .
dockerfile: Dockerfile
ports:
- "2113:22"
- "33066:3306"
network_mode: bridge
restart: always
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
external: true
#!/bin/sh
mysql -u root -p!@#gds$%^ < setting.sql;
#!/bin/sh
create_volume() {
docker volume inspect $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Volume '$1' already exists."
else
docker volume create --name=$1
echo "Volume '$1' created."
fi
}
create_volume dbdata
docker build -t docker_db
docker-compose up -d --build
#원하는 루트 원격 계정 password 입력
grant all privileges on *.* to root@'%' identified by '!@#gds$%^';
flush privileges;
docker_fastapi @ 560d72c9
Subproject commit 560d72c964df1bcb5d468c442a59590f7d9570e1
docker_fastapi_new @ a5d7d902
Subproject commit a5d7d9023b698222b82f1a3df22d378d73cfc74e
# Use a lightweight base image
FROM python:3.9-slim
# Set the working directory
WORKDIR /app
# Copy the Python file into the container
COPY app.py /app
# Install necessary dependencies
RUN pip install Flask requests flask_cors
# Expose the port the app runs on
EXPOSE 3000
# Run the application
CMD ["python", "app.py"]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment