아래 링크 참조
https://93it-serverengineer.tistory.com/11
## docker 재시작
# systemctl restart docker
## docker httpd 검색 및 httpd 최신버전 다운로드
docker search httpd && docker pull httpd
## docker mariadb 검색 및 mariadb 최신버전 다운로드
docker search mariadb && docker pull mariadb
## docker php 검색 및 php 최신버전 다운로드
docker search php && docker pull php
## docker compose yml 파일 만들기
APM 환경 파일을 컨테이너와 연결하여 생성합니다.
vi /root/docker-compose.yml
==================================================================
version: '2.17.2'
services:
httpd:
image: httpd:latest
container_name: httpd
# 서버 부팅시 컨테이너 가동
restart: unless-stopped
ports:
- "80:80"
#- "443:443"
volumes:
- /home/93it/httpd/html/:/usr/local/apache2/htdocs/
#- /home/93it/httpd/conf/:/usr/local/apache2/conf/
#- /home/93it/httpd/logs/:/usr/local/apache2/logs/
mariadb:
image: mariadb
container_name: mariadb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_HOST: localhost
#디비명
MYSQL_DATABASE: 93itdb
#사용자명
MYSQL_USER: 93it
#사용자비밀번호
MYSQL_PASSWORD: 93it_!@#$
#루트계정비밀번호
MYSQL_ROOT_PASSWORD: qwer1234!@#$
SERVICE_TAGS: dev
SERVICE_NAME: mysql
TZ: Asia/Seoul
bitnami/php-fpm:
image: php:8.2-fpm
container_name: php
restart: unless-stopped
volumes:
# php 소스 코드를 사용하기 위해 필수 설정
- /home/93it/httpd/html/:/var/www/html/
ports:
- "9000:9000"
command:
- /bin/sh
- -c
- |
echo "security.limit_extensions = .php .phtml .php3 .php4 .php5 .html .htm" >> /usr/local/etc/php-fpm.d/www.conf
php-fpm
==================================================================
##도커 // 백그라운드로 전체 서비스 (컨테이너) 올리기
[root@Docker-TEST ~]# docker compose up -d
[+] Running 3/3
✔ Container php Started 0.4s
✔ Container mariadb Started 0.6s
✔ Container httpd Started 0.6s
## 도커 // 프로세스 확인
[root@Docker-TEST ~]# docker ps
==================================================================
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad8dcd4ec992 php:8.2-fpm "docker-php-entrypoi…" About a minute ago Up About a minute 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp php
b8ee0ef92b87 mariadb "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mariadb
446286e83ecd httpd:latest "httpd-foreground" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp httpd
==================================================================
[root@Docker-TEST ~]# netstat -ntlp
==================================================================
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8279/docker-proxy
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1198/sshd
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 8172/docker-proxy
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 8200/docker-proxy
tcp6 0 0 :::80 :::* LISTEN 8288/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 1198/sshd
tcp6 0 0 :::9000 :::* LISTEN 8178/docker-proxy
tcp6 0 0 :::3306 :::* LISTEN 8214/docker-proxy
==================================================================
## docker 다운로드 이미지 조회
[root@Docker-TEST ~]# docker images
==================================================================
REPOSITORY TAG IMAGE ID CREATED SIZE
bitnami/php-fpm 8.2 03180b10d3e8 24 hours ago 281MB
bitnami/php-fpm latest 03180b10d3e8 24 hours ago 281MB
php 8.2-fpm 3852a630d409 5 days ago 450MB
httpd latest 192d41583429 10 days ago 145MB
mariadb latest 4a632f970181 2 weeks ago 401MB
==================================================================
echo "93it httpd 도커(docker) 테스트 페이지 입니다." > /home/93it/httpd/html/index.html
[root@Docker-TEST ~]# cat /home/93it/httpd/html/index.html
==================================================================
93it의 Apache 도커(docker) 테스트 페이지 입니다.
==================================================================
## 컨테이너 파일 넣기
docker cp 파일 [컨테이너ID]:디렉토리위치
docker cp test.html 0930144079a7:/usr/local/apache2/htdocs/
Preparing to copy...
Copying to container - 2.048kB
Successfully copied 2.048kB to 0930144079a7:/usr/local/apache2/htdocs/
mkdir
## 컨테이너 파일 꺼내기
docker cp [컨테이너ID]:[경로] [호스트파일 생성 경로]
## httpd 설정파일 꺼내기
mkdir -p /home/93it/httpd/conf
docker cp httpd:/usr/local/apache2/conf /home/93it/httpd/
## mariadb 설정파일 꺼내기
mkdir -p /home/93it/mysql/conf
docker cp mariadb:/etc/mysql/mariadb.cnf /home/93it/mysql/conf/mariadb.cnf
docker cp mariadb:/etc/mysql/mariadb.conf.d /home/93it/mysql/conf/
## mariadb 데이터 베이스 꺼내기
docker cp mariadb:/var/lib/mysql/ /home/93it/mysql/
mv /home/93it/mysql/mysql /home/93it/mysql/data
## php 설정파일 꺼내기 (php.ini php-fpm.conf )
mkdir -p /home/93it/php/
docker cp php:/usr/local/etc /home/93it/php/
## docker compose 파일 수정하기
vi /root/docker-compose.yml
==================================================================
version: '2.17.2'
services:
httpd:
image: httpd:latest
container_name: httpd
# 서버 부팅시 컨테이너 가동
restart: unless-stopped
ports:
- "80:80"
# - "443:443"
volumes:
- /home/93it/httpd/html/:/usr/local/apache2/htdocs/
- /home/93it/httpd/html/:/home/93it/httpd/html/
- /home/93it/httpd/conf/:/usr/local/apache2/conf/
- /home/93it/httpd/logs/:/usr/local/apache2/logs/
mariadb:
image: mariadb
container_name: mariadb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_HOST: localhost
#디비명
MYSQL_DATABASE: 93itdb
#사용자명
MYSQL_USER: 93it
#사용자비밀번호
MYSQL_PASSWORD: 93it_!@#$
#루트계정비밀번호
MYSQL_ROOT_PASSWORD: qwer1234!@#$
SERVICE_TAGS: dev
SERVICE_NAME: mysql
TZ: Asia/Seoul
volumes:
# mariadb data dir
- /home/93it/mysql/data/:/var/lib/mysql/
# mariadb 설정파일
- /home/93it/mysql/conf/mariadb.cnf:/etc/mariadb.cnf
- /home/93it/mysql/conf/mariadb.conf.d/:/etc/mariadb.conf.d/
php:
# Enables debugging capabilities when attached to this container.
tty: true
image: php:8.2-fpm
container_name: php
restart: unless-stopped
volumes:
# php 소스 코드를 사용하기 위해 필수 설정
- /home/93it/httpd/html/:/var/www/html/
# php 설정파일
- /home/93it/php/etc/:/usr/local/etc/
ports:
- "9000:9000"
command:
- /bin/sh
- -c
- |
echo "security.limit_extensions = .php .phtml .php3 .php4 .php5 .html .htm" >> /usr/local/etc/php-fpm.d/www.conf
php-fpm
==================================================================
docker compose down
docker compose up -d
(기타 명령)
# docker compose images // 올려진 서비스 (컨테이너) 가 사용중인 이미지 리스트 출력. (모든 이미지 출력 : docker images)
# docker compose ps // 올려진 서비스 (컨테이너) 출력
# docker compose stop php // 올려진 서비스 (컨테이너) 선택 중지
# docker compose start php // 올려진 서비스 (컨테이너) 선택 시작
# docker rm -v php // 올려진 서비스 (컨테이너) 삭제
# docker compose up -d php // 하나의 서비스 (컨테이너) 만 구동
모든 컨테이너를 더이상 사용하지 않을때 아래와 같이 내립니다.
# docker compose down // 컨테이너 중지 및 삭제
'DEV > Docker-Redhat' 카테고리의 다른 글
0. Docker 명령어 정리 (0) | 2023.04.02 |
---|---|
1. Rocky Linux 8 Docker 설치 (0) | 2023.02.27 |
댓글