๐Ÿณ Docker ๊ธฐ์ดˆ ๋ถ€ํ„ฐ Wordpress ์„œ๋น„์Šค ์ง์ ‘ ๊ตฌํ˜„ ๊นŒ์ง€!

2020๋…„ 12์›” 01์ผ

TOC

Moby-logo.png (601ร—431)

๊ท€์—ฌ์šด Docker Logo!

๐Ÿณ Docker๋ž€!

Docker๋Š” Linux Container ๊ธฐ์ˆ ์„ ์ด์šฉํ•˜์—ฌ ๋งŒ๋“  Container ๊ธฐ์ˆ  ์ค‘ ํ•˜๋‚˜!

๐Ÿ“ฆLinux Container ๊ธฐ์ˆ ์ด๋ž€?

Linux Container๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ฒฉ๋ฆฌ ์‹œํ‚จ๋‹ค๋Š” ๊ฐœ๋…์—์„œ ์ถœ๋ฐœ.

์˜ˆ๋ฅผ ๋“ค์–ด chroot ๋ช…๋ น์–ด๋Š” ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ๋Š” / ๊ฒฝ๋กœ๋ฅผ ๋ณ€๊ฒฝํ•˜์—ฌ ์ ‘๊ทผ ํ•˜๋Š” ํŒŒ์ผ์— ๋Œ€ํ•ด์„œ ์ œ์–ด ๊ฐ€๋Šฅ.

ํ•˜์ง€๋งŒ chroot ๋ช…๋ น์–ด ๋งŒ์œผ๋กœ๋Š” ๋„คํŠธ์›Œํฌ ๋ฐ ํ”„๋กœ์„ธ์Šค ๋“ฑ์„ ์ œํ•œํ•˜๊ธฐ ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์— cgroups ๊ธฐ๋Šฅ์„ ์ด์šฉํ•˜์—ฌ ๊ฐ์ข… ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•ด์„œ ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅ.

์œ„์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ๋“ค์„ ์ด์šฉํ•˜๊ณ  ๋ฐœ์ „ ์‹œ์ผœ์„œ Linux Container ๊ธฐ์ˆ ์ด ํƒ„์ƒ๋จ.

Host์™€ ํ”„๋กœ์„ธ์Šค, ๋ฆฌ์†Œ์Šค ๊ฒฉ๋ฆฌ๋ฅผ ํ†ตํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ฐ€๋‘” ํ™˜๊ฒฝ์„ ์ƒ์„ฑ.

์ด๋ฅผ ํ†ตํ•ด ๊ฐ€์ƒํ™”์™€ ๋‹ฌ๋ฆฌ ์šด์˜์ฒด์ œ๋ฅผ ๊ฐ€์ƒํ™” ํ•˜๊ธฐ ์œ„ํ•œ ์‹œ์Šคํ…œ์ด ๋ณ„๋„๋กœ ํ•„์š”๊ฐ€ ์—†๊ณ  ๊ฒฉ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ Native ์ˆ˜์ค€์œผ๋กœ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•จ.


Docker๋ฅผ ์ด์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ Host์™€ ๊ฒฉ๋ฆฌ๋˜์–ด ์‹คํ–‰์ด ๋˜๊ณ  ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ์œ„ํ•œ ํ™˜๊ฒฝ ์ „์ฒด๊ฐ€ ๋ฏธ๋ฆฌ ์ด๋ฏธ์ง€์— ๋Œ€ํ•ด ์ •์˜๊ฐ€ ๋˜์–ด ์‹คํ–‰์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— host์˜ ํ™˜๊ฒฝ๊ณผ ์ƒ๊ด€์—†์ด ์–ธ์ œ๋‚˜ ๋™์ผํ•œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค!

๋˜ํ•œ ๊ฐ€์ƒํ™”์™€ ๋‹ฌ๋ฆฌ ๊ฒฉ๋ฆฌํ•˜์—ฌ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ‰๋ฒ”ํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•˜๊ณ  ์ข…๋ฃŒํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์ด ๋น ๋ฅธ ์‹คํ–‰๊ณผ ์ข…๋ฃŒ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

์œ„ ์žฅ์ ๋“ค์„ ํ†ตํ•ด์„œ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€์—์„œ ๊ฐœ๋ฐœ๊ณผ ํ…Œ์ŠคํŠธ ๋ฐฐํฌ ๋ชจ๋“  ๊ฒƒ์ด ๋น ๋ฅด๊ณ  ์‹ ์†ํ•˜๊ฒŒ ์ด๋ฃจ์–ด ์งˆ ์ˆ˜ ์žˆ๋‹ค.

Docker๋Š” ๋Œ€๋ถ€๋ถ„์˜ ์šด์˜ ์ฒด์ œ์—์„œ ์ง€์›์„ ํ•˜๋‚˜ Linux Container ๊ธฐ์ˆ ์ด๊ธฐ ๋•Œ๋ฌธ์— Linux ์ด์™ธ์˜ ํ™˜๊ฒฝ, Mac, Windows์—์„œ๋Š” VM์œ„์—์„œ ๋™์ž‘ํ•˜๊ฒŒ ๋œ๋‹ค.

๐Ÿ’ฟ Docker Image

Docker๋Š” ๋งŒ๋“ค์–ด์ง„ Container ํ™˜๊ฒฝ ์ƒํƒœ๋ฅผ Image๋กœ ์ €์žฅ์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›์„ ํ•œ๋‹ค.

์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์ง„ Docker Image๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ์„œ๋ฒ„์—์„œ ๋™์ผํ•˜๊ฒŒ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

์ด๋Ÿฌํ•œ Docker Image๋ฅผ ์—…๋กœ๋“œ ํ•˜์—ฌ ๋ณด๊ด€ํ•˜๊ณ  ๋ฒ„์ „ ๊ด€๋ฆฌ ํ•˜๋Š” ๊ณณ์ด ์žˆ๋Š”๋ฐ ๊ทธ ๊ณณ์„ registry ๋ผ๊ณ  ํ•œ๋‹ค.

๋Œ€ํ‘œ์ ์ธ registry๋กœ Docker Hub๊ฐ€ ์žˆ๋‹ค.

๐Ÿ—‚ Dockerfile

Dockerfile์€ image๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ Script ํŒŒ์ผ์ด๋‹ค.

Dockerfile์€ Image๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์ž‘์—…์ด ๊ธฐ์žฌ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Build๊ฐ€ ๋˜๋ฉด ๋™์ผํ•œ Image๋ฅผ ๋งŒ๋“ค์–ด๋‚ด๊ฒŒ ๋œ๋‹ค.

์ด ์ ์„ ์ด์šฉํ•˜์—ฌ ๋ฐฐํฌ ์‹œ์— Build ํ›„ ๋‚˜์˜จ ๋ช‡ ๊ธฐ๊ฐ€ ์ด์ƒ๋˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐฐํฌํ•˜๊ธฐ ๋ณด๋‹ค๋Š” Dockerfile๋ฅผ ์ด์šฉํ•˜์—ฌ build ํ•˜์—ฌ ๋ฐฐํฌ๋ฅผ ํ•œ๋‹ค.

๐Ÿ“Dockerfile ์ž‘์„ฑ ๋ฌธ๋ฒ•!

๐Ÿ“‹ FROM

๊ธฐ๋ณธ์ ์œผ๋กœ Dockerfile์€ ์–ด๋–ค ์ด๋ฏธ์ง€๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ง€์— ๋Œ€ํ•ด์„œ ์ •์˜๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค.

# FROM <image-name>:<label>
FROM debian:buster

์œ„์™€ ๊ฐ™์ด FROM ๋’ค์— ์ด๋ฏธ์ง€์˜ ์ด๋ฆ„์ด ์˜ค๊ณ  ๊ทธ ๋‹ค์Œ์—๋Š” ์ด๋ฏธ์ง€์˜ label์ด ์˜ค๊ฒŒ ๋œ๋‹ค.

์—ฌ๊ธฐ์„œ ์ด๋ฏธ์ง€๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ **Docker Hub** ์™€ Alias๊ฐ€ ๋˜์–ด ์žˆ์–ด์„œ ๋‹ค๋ฅธ registry์—์„œ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ ธ ์˜ฌ ๋•Œ์—๋Š” registry์˜ ์ „์ฒด url๋ฅผ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑ์„ ํ•ด์•ผ ํ•œ๋‹ค.

๐Ÿ“‹ RUN

Dockerfile์—์„œ ์ด๋ฏธ์ง€ ๋‚ด๋ถ€์—์„œ ์‹คํ–‰ ๋˜์–ด์•ผ ํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

# RUN <command>
RUN apt update -y

์œ„์™€ ๊ฐ™์ด RUN ๋’ค์— ์‹คํ–‰์ด ํ•„์š”ํ•œ ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑ์„ ํ•˜์—ฌ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

์ด๋•Œ ์œ„์™€ ๊ฐ™์ด ์‚ฌ์šฉ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋งŒ์ด ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์ง์ ‘ ์‹คํ–‰ ๋˜์–ด์•ผ ํ•˜๋Š” ๊ฒฝ๋กœ๋ฅผ ์ง์ ‘ ์ ์–ด ์ฃผ๋Š” ๋ฐฉ๋ฒ•๊ณผ ์ธ์ž์— ๋Œ€ํ•ด์„œ ํ™•์‹คํ•˜๊ฒŒ arrayํ˜•ํƒœ๋กœ ์ •์˜ ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•๋„ ์กด์žฌ ํ•œ๋‹ค.

RUN /bin/bash -c 'echo "Hello World!"'
RUN ["/bin/bash", "-c" "echo 'Hello World!'"]

์ด๋•Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ ํ›„์— ๋งŒ๋“ค์–ด์ง€๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋ ˆ์ด์–ด ๋ณ„๋กœ ์ €์žฅ์„ ํ•˜๊ฒŒ ๋˜์–ด์„œ Dockerfile์—์„œ ์ˆ˜์ •์„ ํ•˜์—ฌ๋„ ์ด์ „ ๋ ˆ์ด์–ด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋น ๋ฅด๊ฒŒ ๋นŒ๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

๐Ÿ“‹ COPY

Docker image๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ๋‚ด๋ถ€์— Sourcefile๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ์ด๋™์ด ํ•„์š” ํ•  ๋•Œ๊ฐ€ ์žˆ๋Š”๋ฐ ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

# COPY <src> <dst>
COPY init.sh /

๐Ÿ“‹ ADD

Dockerfile์—๋Š” COPY ์™€ ์œ ์‚ฌํ•œ ์„ฑ๊ฒฉ์ธ ADD ๋ช…๋ น์–ด๊ฐ€ ์กด์žฌ๋ฅผ ํ•œ๋‹ค.

ADD ๋Š” COPY ์™€ ๋‹ฌ๋ฆฌ ํŒŒ์ผ์˜ src ๋ถ€๋ถ„์— url๋ฅผ ์ ๊ฒŒ ๋˜๋ฉด ์ž๋™์œผ๋กœ ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›์•„์„œ ๋ณต์‚ฌ๋ฅผ ํ•˜๊ณ  ์••์ถ• ํŒŒ์ผ์˜ ๊ฒฝ์šฐ์—๋Š” ์••์ถ•์„ ํ•ด์ œํ•ด์„œ ์ „๋‹ฌํ•˜๊ฒŒ ๋˜๋Š” ํŠน์ง•์ด ์กด์žฌํ•œ๋‹ค.

# ADD <src(url)> <dest>
ADD <https://www.docker.com/sites/default/files/d8/2019-07/Moby-logo.png> /

์ด๋Ÿฌํ•œ ํŠน์„ฑ์ด ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— COPY ์™€ ADD ๋ฅผ ์ ์ ˆํžˆ ์„ ํƒ์„ ํ•˜์—ฌ์„œ ์‚ฌ์šฉ์„ ํ•ด์•ผ ํ•œ๋‹ค.

๐Ÿ“‹ ENV

Dockerfile์—์„œ๋Š” ๋‚ด๋ถ€ ์ด๋ฏธ์ง€์—์„œ ์„ค์ •๋˜๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜์— ๋Œ€ํ•ด์„œ๋„ ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

# ENV name=value
ENV DEV_ENV=true

๐Ÿ“‹ WORKDIR

Dockerfile์—์„œ ์ž‘์—… ํ•˜๋Š” ๊ฒฝ๋กœ์— ๋Œ€ํ•ด์„œ ์ •์˜๋ฅผ ํ•  ๋•Œ์—๋Š” WORKDIR ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •์˜๋ฅผ ํ•˜๊ฒŒ ๋œ๋‹ค.

# WORKDIR <dir>
WORKDIR /root

๐Ÿ“‹ USER

WORKDIR ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž‘์—… ๊ฒฝ๋กœ๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์ด ์ž‘์—…ํ•˜๋Š” ์‚ฌ์šฉ์ž์— ๋Œ€ํ•ด์„œ๋„ ์ •์˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

 # USER <user>[:<group>] | <UID>[:<GID>]
USER 0:0

๋‹จ ์ด๋•Œ ์‚ฌ์šฉ ๋˜๋Š” user์— ๋Œ€ํ•ด์„œ๋Š” ๋ฏธ๋ฆฌ RUN ๋ฅผ ์ด์šฉํ•ด์„œ user์™€ group๋ฅผ ์ถ”๊ฐ€๋ฅผ ํ•˜๊ฑฐ๋‚˜ ์ด๋ฏธ์ง€์— ๋“ฑ๋ก์ด ๋œ user์—ฌ๋งŒ ์ž‘๋™์„ ํ•˜๊ฒŒ ๋œ๋‹ค.

๐Ÿ“‹ RUN

RUN ๋ฅผ ํ•  ๋•Œ์— ์‚ฌ์šฉ์ด ๋˜๋Š” ๊ธฐ๋ณธ shell์— ๋Œ€ํ•ด ์•„๋ž˜์™€ ๊ฐ™์ด ์ •์˜๊ฐ€ ๊ฐ€๋Šฅ ํ•˜๋‹ค.

# SHELL [<executable>, <parameters>]
SHELL ["/bin/bash", "-"]

๐Ÿ“‹ ARG

Dockerfile์€ image๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋Š” script ์ด๋ฏ€๋กœ ๋™์ ์œผ๋กœ ํ• ๋‹น์ด ๊ฐ€๋Šฅํ•œ ARG ๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅ์„ ํ•˜๋‹ค.

# ARG <name>[=<default value>]
ARG user=root

์ด๋•Œ ARG ๋ช…๋ น์–ด๋กœ ์ •์˜ํ•˜๊ฒŒ ๋œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋Š” ๋™์ผํ•œ ARG ๋ณ€์ˆ˜๋ฅผ ์žฌ์ •์˜ ํ•œ๋‹ค.

๋นŒ๋“œ ํ•  ๋•Œ ๋งŒ์•ฝ arg์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ ํ•œ๋‹ค.

$ docker build --build-arg user=jaeskim .

๋งŒ์•ฝ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ arg๋ฅผ ์ด์šฉํ•˜์—ฌ ์žฌ์ •์˜ ํ•˜์—ฌ ์‚ฌ์šฉ์„ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ๋‹ค.

ARG TEST
ENV TEST=${TEST:-hello_world}
RUN echo $TEST

๐Ÿ“‹ EXPOSE

์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์—์„œ ๋„คํŠธ์›Œํฌ ํฌํŠธ๋ฅผ ์ˆ˜์‹  ๋Œ€๊ธฐ ํ•จ์„ Docker์—๊ฒŒ ๋ฏธ๋ฆฌ ์•Œ๋ ค์ค„ ์ˆ˜ ์žˆ๋Š”๋ฐ ์ด๋•Œ EXPOSE ๋ช…๋ น์–ด๋กœ ์„ค์ •ํ•œ๋‹ค.

# EXPOSE <port> | <port><protocol>
EXPOSE 80
EXPOSE 443/tcps

๊ธฐ๋ณธ์ ์œผ๋กœ protocol์— ๋Œ€ํ•ด์„œ ์ •์˜๋ฅผ ํ•˜์ง€ ์•Š๊ฒŒ ๋œ๋‹ค๋ฉด tcp๋กœ ์ž‘๋™์„ ํ•˜๊ฒŒ ๋˜๊ณ , ์—ฌ๊ธฐ์„œ ์ •์˜๋ฅผ ํ•˜์˜€๋‹ค๊ณ  ๋ฐ”๋กœ HOST์™€ port๊ฐ€ ์—ฐ๊ฒฐ์ด ๋˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— run time์‹œ์— port binding ์ž‘์—…์ด ์ˆ˜ํ–‰ ๋˜์–ด์•ผ ํ•œ๋‹ค.

๐Ÿ“‹ CMD, ENTRYPOINT

์ด์ œ Dockerfile ์—์„œ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์˜ฌ๋ผ๊ฐ€๊ณ  ์‹คํ–‰์ด ๋ช…๋ น์–ด์— ๋Œ€ํ•ด์„œ ์ •์˜ ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„ ๋ณธ๋‹ค.

CMD , ENTRYPOINT ๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •์˜๋ฅผ ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ๊ฐ ๊ฐ ์‚ฌ์šฉ ํ•  ๋•Œ์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•  ๋•Œ์˜ ์˜ˆ์ œ์™€ ํ•จ๊ป˜ ์ฐจ์ด๋ฅผ ์•Œ์•„ ๋ณธ๋‹ค.

CMD ["echo", "hello"]

์œ„์™€ ๊ฐ™์ด ๋งŒ๋“ค์–ด์ง„ dockerfile๋ฅผ ๋นŒ๋“œ ํ›„ ์‹คํ–‰์„ ํ•˜๊ฒŒ ๋˜๋ฉด echo hello ๊ฐ€ ์ž‘๋™ ํ•˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์ด ๋•Œ docker run test:cmd echo hi ์™€ ๊ฐ™์ด ๋งˆ์ง€๋ง‰์— ์‹คํ–‰ ์ธ์ž๋ฅผ ์ „๋‹ฌ ํ•˜๊ฒŒ ๋˜๋ฉด echo hi ๊ฐ€ ์‹คํ–‰์ด ๋˜๊ณ  inspect ๋ช…๋ น์–ด๋กœ ํ™•์ธ์„ ํ•ด๋ณด๋ฉด CMD ๋ถ€๋ถ„์˜ ์ •๋ณด๊ฐ€ ์ƒˆ๋กœ ์ •์˜ํ•œ ๋‚ด์šฉ์œผ๋กœ ๋ณ€๊ฒฝ์ด ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ๊ฐ€ ์žˆ๋‹ค.

์ด๋ฒˆ์—๋Š” ENTRYPOINT ๋ช…๋ น์–ด๋ฅผ ๋‹จ๋…์œผ๋กœ ์‚ฌ์šฉ์„ ํ•ด๋ณธ๋‹ค.

ENTRYPOINT ["echo", "hello"]

์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ•œ dockerfile๋ฅผ ๋นŒ๋“œ ํ›„ ์‹คํ–‰ํ•˜๋ฉด ๋‹น์—ฐํ•˜๊ฒŒ hello ๊ฐ€ ์ถœ๋ ฅ์ด ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์ด ๋•Œ docker run test:entrypoint echo world ๋กœ ์‹คํ–‰์„ ํ•˜๊ฒŒ ๋˜๋ฉด hello echo world ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์ด๋Ÿฌํ•œ ๋™์ž‘์ด ๋‚˜์˜จ ์ด์œ ๋ฅผ inspect ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์•Œ์•„๋ณธ๋‹ค.

...
"Cmd": [
  "echo",
  "world"
],
"Image": "test:entrypoint",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
  "echo",
  "hello"
],
...

dcokerfile์—์„œ ์ž‘์„ฑ๋œ ENTRYPOINT ๋Š” ์žฌ์ •์˜ ๋˜์ง€ ์•Š๊ณ  CMD ๋ถ€๋ถ„์€ ์žฌ์ •์˜ ๋˜์—ˆ์ง€๋งŒ ENTRYPOINT + CMD ๋ถ€๋ถ„์ด ์ด์–ด์ ธ์„œ ์ž‘๋™์„ ํ•œ๋‹ค.

์ฆ‰ ENTRYPOINT ์—๋Š” ์„œ๋น„์Šค๋กœ ๋Œ์•„๊ฐ€๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์œผ๋กœ ์ •์˜๋ฅผ ํ•˜๊ณ  CMD ๋ถ€๋ถ„์„ ์ถ”๊ฐ€ ์ ์œผ๋กœ ์ธ์ž๋ฅผ ํ†ตํ•ด ์ •๋ณด๋ฅผ ์ „๋‹ฌ ํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฒƒ์ด ๊ถŒ์žฅ ๋œ๋‹ค.

๐Ÿ“‹ VOLUME

Docker์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ด๋ฏธ์ง€ ๋ ˆ์ด์–ด์— ์ €์žฅ์„ ํ•˜๊ฒŒ ๋˜๋ฏ€๋กœ container๊ฐ€ ๋‚ด๋ ค๊ฐ€๊ณ  ์ƒˆ๋กœ์šด ๊ฒƒ์„ ์˜ฌ๋ฆด ๋•Œ๋งˆ๋‹ค ์ดˆ๊ธฐ ์„ค์ •๋œ ๋ฐ์ดํ„ฐ๋กœ ์ดˆ๊ธฐํ™” ๋˜๋Š” ํœ˜๋ฐœ์„ฑ์ด๋ผ๋Š” ํŠน์ง•์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

์ด๋•Œ log file์ด๋‚˜ db์™€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋Š” ํœ˜๋ฐœ์„ฑ์ด ์•„๋‹Œ ๋น„ ํœ˜๋ฐœ์„ฑ์œผ๋กœ ๊ด€๋ฆฌ ๋˜์–ด์•ผ ํ•˜๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ํŠน์ • ํด๋”๋ฅผ ๊ธฐ๋ณธ volume์œผ๋กœ ์ €์žฅ์„ ํ•˜์ง€ ์•Š๊ณ  ๋”ฐ๋กœ ์ €์žฅ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

# VOLUME [<dir>]
VOLUME ["/data"]

๐Ÿ“‹ ONBUILD

๋งŒ์•ฝ ๋งŒ๋“ค์–ด์ง„ image๋ฅผ ๊ฐ€์ง€๊ณ  FROM๋ฅผ ํ•  ๋•Œ์— ๋ฏธ๋ฆฌ ์ˆ˜ํ–‰ ๋˜์–ด์•ผ ํ•˜๋Š” ์ž‘์—…์ด ์žˆ์„ ๋•Œ ONBUILD ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด python build ์— ๊ด€๋ จ๋œ ์ด๋ฏธ์ง€๋ผ๋ฉด FROM ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด build๋ฅผ ํ•  ๋•Œ src ํŒŒ์ผ๋“ค์„ ๊ฐ€์ ธ์™€ ์‚ฌ์šฉ์„ ํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

# ONBUILD <INSTRUCTION>
ONBUILD ADD . /app/src
ONBUILD RUN /usr/local/bin/python-build --dir /app/src

๐Ÿ“‹ STOPSIGNAL

๊ธฐ๋ณธ์ ์œผ๋กœ Docker Container๋ฅผ ์ข…๋ฃŒํ•˜๊ฒŒ ๋˜๋ฉด ๋‚ด๋ถ€์—์„œ ์ž‘๋™ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์—๊ฒŒ SIGTERM ๋ฅผ ๋ณด๋‚ด๊ฒŒ ๋˜๋Š”๋ฐ ์ด ๋•Œ ๋ณด๋‚ด์ง€๋Š” SIGNAL์— ๋Œ€ํ•ด์„œ ์ •์˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

# STOPSIGNAL signal
STOPSIGNAL SIGKILL

๐Ÿ“‹ HEALTHCHECK

DockerContainer๊ฐ€ ์˜ฌ๋ผ๊ฐ”์„ ๋•Œ ์‹ค์ œ๋กœ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ ํ•˜๋Š” ์ง€์— ๋Œ€ํ•ด์„œ Healthcheck๊ฐ€ ๊ฐ€๋Šฅํ•œ๋ฐ ์ด๊ฒƒ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•œ๋‹ค.

# HEALTHCHECK [OPTIONS] CMD command
HEALTHCHECK --interval=5m --timeout=3s \\
  CMD curl -f <http://localhost/> || exit 1

์—ฌ๊ธฐ์„œ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์€ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ์ด ๋œ๋‹ค.

  • -interval=DURATION (default: 30s)
  • -timeout=DURATION (default: 30s)
  • -start-period=DURATION (default: 0s)
  • -retries=N (default: 3)

๐Ÿ“‹ LABEL

์ƒ์„ฑ๋œ image์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ •๋ณด๋ฅผ ๋‹ด์„ ๋•Œ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

# LABEL <name>=<value>
LABEL maintainer="jaeskim <jaeskim.student.42seoul.kr>"

๐Ÿ–ฅ docker ๋ช…๋ น์–ด

docker๋ฅผ ๊ด€๋ฆฌ ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋‹ค์–‘ํ•œ ๋ช…๋ น์–ด๊ฐ€ ์กด์žฌ ํ•˜๋Š”๋ฐ ๊ทธ ์ค‘ ์ž์ฃผ ์‚ฌ์šฉ๋˜๊ณ  ์ค‘์š”ํ•œ ๋ช…๋ น์–ด์— ๋Œ€ํ•ด์„œ ์•Œ์•„ ๋ณธ๋‹ค.

์˜ต์…˜์ด ๋ฐฉ๋Œ€ํ•˜์—ฌ ๋ชจ๋“  ๋‚ด์šฉ์„ ์„ค๋ช…์„ ๋ชปํ•˜๋ฏ€๋กœ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์ด ์žˆ์„ ๋•Œ์—๋Š” reference site์—์„œ ํ™•์ธ ํ•˜์—ฌ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

โš™๏ธ build

build ๋ช…๋ น์–ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ Dockerfile ๋ฅผ ์ด์šฉํ•˜์—ฌ image๋ฅผ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉ์„ ํ•˜๊ฒŒ ๋œ๋‹ค.

# docker build [OPTIONS] PATH | URL | -
$ docker build --tag test:v1 .

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -t, --tag name:tag ์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ธ์ž๋ฅผ ์ฃผ๊ณ  ์ƒ์„ฑ๋˜๋Š” image์˜ tag๋ฅผ ์ง€์ •ํ•˜๋Š” ์˜ต์…˜์ด๋‹ค.
  • -f, --file string ํŠน์ • Dockerfile ๋ฅผ ์ง€์ • ํ•˜์—ฌ์„œ ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
  • --build-arg Dockerfile์— ์ •์˜๋œ ๋ณ€์ˆ˜์— ๋Œ€ํ•ด์„œ ๊ฐ’์„ ์ง€์ •ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
  • --no-cache build ํ•  ๋•Œ cache๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๋„๋ก ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

๐Ÿƒ๐Ÿปโ€โ™‚๏ธ run

run ๋ช…๋ น์–ด๋Š” ๋งŒ๋“ค์–ด์ง„ image๋ฅผ ๊ฐ€์ง€๊ณ  ์‹คํ–‰ ํ•  ๋•Œ ์‚ฌ์šฉ์„ ํ•˜๊ฒŒ ๋œ๋‹ค.

# docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
$ docker run -p 8080:80 -it --rm --name testserver test:v1 /bin/bash

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -p, --publish (hostport:containerport) container ๋‚ด๋ถ€์˜ port์™€ host์˜ port๋ฅผ binding ํ•  ๋•Œ ์‚ฌ์šฉ์ด ๋œ๋‹ค.
  • -i, --interactive STDIN๋ฅผ container์™€ ์—ฐ๊ฒฐ ํ•˜์—ฌ์„œ ๋™์ ์œผ๋กœ ๋ฐ˜์‘ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.
  • -t, --tty tty์ฒ˜๋Ÿผ ์ž‘๋™ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.
  • --rm container๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ์ž๋™์œผ๋กœ image๋ฅผ ์ง€์›Œ์ฃผ๋Š” ์˜ต์…˜์ด๋‹ค.
  • -e, --env ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ •์˜ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค.
  • --name ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ์ •์˜ ํ•œ๋‹ค.
  • -d, --detach background๋กœ container๊ฐ€ ๋™์ž‘ํ•˜๊ฒŒ ๋˜๊ณ  ID๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
  • -v, --volume volume๋ฅผ ๋งˆ์šดํŠธ ์‹œํ‚ฌ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

โœ‹ stop

stop ๋ช…๋ น์–ด๋Š” container๋ฅผ ์ค‘์ง€ ์‹œํ‚ฌ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

# docker stop [OPTIONS] CONTAINER [CONTAINER...]
$ docker stop testserver
  • -t, --time STOPSIGNAL ์‹œ๊ทธ๋„์„ ๋ณด๋‚ด๊ณ  ๋ช‡์ดˆ๊ฐ„ ๋Œ€๊ธฐ๋ฅผ ํ• ์ง€ ์„ค์ •ํ•˜๋Š” ์˜ต์…˜์ด๋‹ค.

๐ŸŽฌ start

start ๋ช…๋ น์–ด๋Š” ๋ฉˆ์ถฐ์ง„ container๋ฅผ ๋‹ค์‹œ ๋™์ž‘ ์‹œํ‚ฌ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

# docker start [OPTIONS] CONTAINER [CONTAINER...]
docker start testserver

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -a, --attach stdout/stderr ์—ฐ๊ฒฐ ํ•œ๋‹ค.
  • -i, --interactive STDIN๋ฅผ container์™€ ์—ฐ๊ฒฐ ํ•˜์—ฌ์„œ ๋™์ ์œผ๋กœ ๋ฐ˜์‘ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

โš“๏ธ attach

attach ๋ช…๋ น์–ด๋Š” ์‹คํ–‰๋œ container์˜ ํ”„๋กœ์„ธ์Šค์— ์—ฐ๊ฒฐ ํ•  ๋•Œ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

# docker attach [OPTIONS] CONTAINER
docker attach testserver

์ด ๋•Œ ์ „๋‹ฌ ์—ฐ๊ฒฐํ•˜๊ฒŒ ๋˜๋Š” ํ”„๋กœ์„ธ์Šค๋Š” cmd, entrypoint๋กœ ์ •์˜๋œ ํ”„๋กœ์„ธ์Šค ์ด๋ฏ€๋กœ ์—ฌ๊ธฐ์„œ ctr-c ๋ฅผ ๋ˆŒ๋Ÿฌ ์ข…๋ฃŒํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ฉˆ์ถ”๋ฏ€๋กœ ctr-p, ctr-q ๋กœ deattach๋ฅผ ํ•˜์—ฌ ๋‚˜์˜ค๋Š” ๊ฒƒ์ด ๊ถŒ์žฅ์ด ๋œ๋‹ค.

๐Ÿ“ก exec

exec ๋ช…๋ น์–ด๋Š” ์‹คํ–‰๋œ container์—๊ฒŒ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰์„ ์‹œํ‚ฌ ๋•Œ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

# docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
docker exec -it testserver /bin/bash

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -d, --detach ์‹คํ–‰ํ•œ ํ”„๋กœ์„ธ์Šค์™€ ์—ฐ๊ฒฐ ์‹œํ‚ค์ง€ ์•Š๊ณ  ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ๋™์ž‘ ํ•˜๊ฒŒ ํ•œ๋‹ค.
  • -e, --env ์ปจํ…Œ์ด๋„ˆ์—๊ฒŒ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌ.
  • -i, --interactive STDIN๋ฅผ container์™€ ์—ฐ๊ฒฐ ํ•˜์—ฌ์„œ ๋™์ ์œผ๋กœ ๋ฐ˜์‘ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.
  • -t, --tty tty์ฒ˜๋Ÿผ ์ž‘๋™ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.
  • -u --user ์‹คํ–‰ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์˜ ์œ ์ €๋ฅผ ์ •์˜ ํ•œ๋‹ค. <name|uid>[:<group|gid>]
  • -w, --workdir ์‹คํ–‰๋˜๋Š” ์ž‘์—… ๊ฒฝ๋กœ๋ฅผ ์ง€์ •ํ•œ๋‹ค.

๐Ÿ—‚ ps

ps ๋ช…๋ น์–ด๋Š” continaer๋กœ ๋ชฉ๋ก์„ ํ™•์ธ ํ•  ๋•Œ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

# docker ps [OPTIONS]
docker ps -a

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -a, --all ๋ชจ๋“  container ๋ชฉ๋ก์„ ์ถœ๋ ฅ! (๊ธฐ๋ณธ๊ฐ’์€ ์ž‘๋™ ์ค‘์ธ continer๋งŒ ์ถœ๋ ฅํ•จ)

๐Ÿ“€ images

images ๋ช…๋ น์–ด๋Š” images์˜ ๋ชฉ๋ก์„ ํ™•์ธ๐Ÿ‡ง๐Ÿ‡ธ ํ•  ๋•Œ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

# docker images [OPTIONS] [REPOSITORY[:TAG]]
docker images -a

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -a, --all ๋ชจ๋“  images ๋ชฉ๋ก์„ ์ถœ๋ ฅ! (๊ธฐ๋ณธ๊ฐ’์€ ์ค‘๊ฐ„ layer ๋‹จ๊ณ„์˜ images๋Š” ์ˆจ๊น€)

๐Ÿ–จ inspect

inspect ๋ช…๋ น์–ด๋Š” container object์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅ ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

# docker inspect [OPTIONS] NAME|ID [NAME|ID...]
docker inspect testserver

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -f, --format ์˜ต์…˜๊ณผ ํ•จ๊ป˜ ์ฃผ์–ด์ง„ template ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ๋ฅผ ํ•œ๋‹ค.

๐Ÿ—‘ rm

rm ๋ช…๋ น์–ด๋Š” contiainer๋ฅผ ์ œ๊ฑฐ ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

# docker rm [OPTIONS] CONTAINER [CONTAINER...]
docker rm testserver

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -f, --force ์ž‘๋™ ์ค‘์ธ container์—ฌ๋„ SIGKILL๋ฅผ ๋ณด๋‚ด์–ด ๊ฐ•์ œ๋กœ ์ข…๋ฃŒํ›„ ์‚ญ์ œ๋ฅผ ํ•œ๋‹ค.

โœจ rmi

rmi ๋ช…๋ น์–ด๋Š” images๋ฅผ ์ œ๊ฑฐ๋ฅผ ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

# docker rmi [OPTIONS] IMAGE [IMAGE...]
docker rmi test

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ์ž‘๋™์ด ๋˜๋Š”๋ฐ ์ž์ฃผ ์‚ฌ์šฉ ๋˜๋Š” ์˜ต์…˜์— ๋Œ€ํ•ด์„œ๋งŒ ์„ค๋ช…์„ ํ•œ๋‹ค.

  • -f, --force ๊ฐ•์ œ๋กœ image๋ฅผ ์ œ๊ฑฐํ•œ๋‹ค.

๐Ÿ›Ž commit

commit ๋ช…๋ น์–ด๋Š” container์˜ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ณ  ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

# docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
docker commit testserver testserver:v2
  • -a, --author author์— ๋Œ€ํ•ด ์ •์˜ ํ•œ๋‹ค.
  • -c, --change ์ƒ์„ฑ๋œ image์— Dockerfile ๋ช…๋ น์–ด๋ฅผ ์ ์šฉ.
  • -m, --message ์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€ ์ž‘์„ฑ.
  • -p, --pause commit ์‹œ์ ์— container ์ผ์‹œ ์ค‘๋‹จ. (Default true)

๐Ÿณ Docker๋ฅผ Wordpress ์„œ๋น„์Šค ์ง์ ‘ ๊ตฌํ˜„!

์ด์ œ ์œ„์—์„œ ์ •๋ฆฌํ•œ ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ Wordpress ์„œ๋น„์Šค๋ฅผ ์ง์ ‘ ๊ตฌํ˜„์„ ํ•œ๋‹ค.!

์ผ๋‹จ ์‹œ์ž‘ ํ•˜๊ธฐ ์ „์— ์•„๋ž˜์™€ ๊ฐ™์€ ์กฐ๊ฑด์œผ๋กœ ๊ตฌํ˜„์„ ํ•  ์˜ˆ์ •์ด๋‹ค.

  • Docker Container ์—์„œ๋Š” web server๋ฅผ Nginx๋กœ ์‚ฌ์šฉ์„ ํ•˜๊ณ , base Images๋Š” debian buster๋กœ ์„ค์ •ํ•œ๋‹ค.
  • WebServer๋Š” ๋™์‹œ์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ ํ•˜๋ฉฐ, ์„œ๋น„์Šค์˜ ๋ชฉ๋ก์€ WordPress, phpMyAdmin, MySQL ์ด๋‹ค.
  • WebServer๋Š” SSL protocol์ด ์ ์šฉ์ด ๋˜์–ด์•ผ ํ•œ๋‹ค.
  • Url์— ๋”ฐ๋ผ์„œ ๊ฐ ์„œ๋น„์Šค๋กœ ์—ฐ๊ฒฐ์ด ๋˜์–ด์•ผ ํ•œ๋‹ค.
  • ๋น„ํ™œ์„ฑํ™”๊ฐ€ ๊ฐ€๋Šฅํ•œ autoindex๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋น„์Šค๊ฐ€ ๋™์ž‘ ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ํ™•์ธ์ด ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค.

๐Ÿ” SSL ์„ค์ • ํ•˜๊ธฐ!

์ผ๋‹จ Makefile๋ฅผ ๋จผ์ € ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž‘์„ฑ์„ ํ•ด๋ณธ๋‹ค.

FROM debian:buster
LABEL maintainer="jaeskim <jaeskim.student.42seoul.kr>"

# init setup
RUN apt update -y; apt upgrade -y

# install dependency
RUN apt install nginx curl -y

์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•œ dockerfile๋ฅผ ๊ฐ€์ง€๊ณ  ์ผ๋‹จ build๋ฅผ ํ•˜์—ฌ์„œ ๋‚ด๋ถ€์— ์ ‘๊ทผํ•˜์—ฌ์„œ SSL ์„ค์ •์„ ์‹œ์ž‘ํ•œ๋‹ค.

$ docker build --tag ft_server:v1 .
$ docker run -it --name ft_server ft_server:v1 /bin/bash

SSL ๋ฅผ ์ ์šฉ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ธ์ฆ์„œ๊ฐ€ ํ•„์š”ํ•œ๋ฐ ์ธ์ฆ์„œ๋ฅผ CA์— ๋“ฑ๋ก์„ ํ•˜์—ฌ ์‚ฌ์šฉ์„ ํ•˜๊ฒŒ ๋˜๋ฉด ๋น„์šฉ์ด ๋ฐœ์ƒํ•˜๋ฏ€๋กœ OpenSSL๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž์ฒด ์„œ๋ช… ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ ๋ฐ›์•„์„œ ๊ตฌํ˜„์„ ํ•œ๋‹ค.

SSL ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜์˜ ์ ˆ์ฐจ๊ฐ€ ์ง„ํ–‰๋˜์–ด์•ผ ํ•œ๋‹ค.

  1. ๊ฐœ์ธํ‚ค ์ƒ์„ฑ

    openssl genrsa -out ft_server.localhost.key 4096
  2. ๊ฐœ์ธํ‚ค๋ฅผ ๊ฐ€์ง€๊ณ  ์ž์ฒด ์„œ๋ช… ์ธ์ฆ์„œ ์ƒ์„ฑ

    openssl req -x509 -nodes -days 365 -key ft_server.localhost.key -out ft_server.localhost.crt -subj "/C=KR/ST=SEOUL/L=Gaepo-dong/O=42Seoul/OU=jaeskim/CN=localhost"

์ด์ œ ์œ„์—์„œ ๋งŒ๋“  ft_server.localhost.key, ft_server.localhost.crt ํŒŒ์ผ์„ /etc/ssl/certs ์™€ /etc/ssl/private ๊ฒฝ๋กœ๋กœ ์ด๋™์„ ์‹œ์ผœ์ค€๋‹ค.

๊ฐ ์ธ์ฆ์„œ ํŒŒ์ผ์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ 644 ๋ณ€๊ฒฝ์„ ํ•˜์—ฌ์„œ root ์†Œ์œ ์ž ๋งŒ์ด ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•œ๋‹ค.

์ด์ œ /etc/nginx/sites-available/default ํŒŒ์ผ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •์„ ํ•œ๋‹ค.

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	return 301 https://$host$request_uri;
}

server {
	listen 443 ssl default_server;
	listen [::]:443 ssl default_server;

	server_name _;

	ssl_certificate /etc/ssl/certs/ft_server.localhost.crt;
	ssl_certificate_key /etc/ssl/private/ft_server.localhost.key;

	root /var/www/html;

	index index.html index.htm index.nginx-debian.html;

	location / {
		try_files $uri $uri/ =404;
	}
}

443 ์œผ๋กœ ๋“ค์–ด์˜จ ์š”์ฒญ์€ ์„ค์ •ํ•œ ssl_certificate, ssl_certificate_key ํŒŒ์ผ๋“ค์„ ์ด์šฉํ•˜์—ฌ ssl ํ†ต์‹ ์„ ํ•˜๊ฒŒ ๋˜๊ณ , ๊ธฐ์กด 80 ์œผ๋กœ ๋“ค์–ด์˜จ ์š”์ฒญ์€ https ์š”์ฒญ์„ redirect ํ•˜๋„๋ก ํ•˜์˜€๋‹ค.

continer ๋‚ด๋ถ€์—์„œ ์ˆ˜์ •ํ•œ ํŒŒ์ผ์„ continer ์™ธ๋ถ€๋กœ ๋ณต์‚ฌํ•˜๊ธฐ ์œ„ํ•˜์—ฌ docker cp ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์™ธ๋ถ€๋กœ ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ค๊ณ  ์œ„์—์„œ ํ–ˆ๋˜ ์ž‘์—…๋“ค์„ dockerfile์— ๋‹ค์‹œ ์ •์˜๋ฅผ ํ•ด์ฃผ์—ˆ๋‹ค.

FROM debian:buster
LABEL maintainer="jaeskim <jaeskim.student.42seoul.kr>"

# init setup
RUN apt update -y; apt upgrade -y

# install dependency
RUN apt install nginx vim curl -y

# environment
ENV AUTO_INDEX=false

# setup SSL
RUN openssl genrsa -out ft_server.localhost.key 4096; \
	openssl req -x509 -nodes -days 365 \
	-key ft_server.localhost.key \
	-out ft_server.localhost.crt \
	-subj "/C=KR/ST=SEOUL/L=Gaepo-dong/O=42Seoul/OU=jaeskim/CN=localhost"; \
	chmod 644 ft_server.localhost.*; \
	mv ft_server.localhost.crt /etc/ssl/certs/;	\
	mv ft_server.localhost.key /etc/ssl/private/;

COPY src/nginx-sites-available-default.conf /etc/nginx/sites-available/default

๐Ÿ—‚ ๋น„ํ™œ์„ฑํ™”๊ฐ€ ๊ฐ€๋Šฅํ•œ autoindex ๊ธฐ๋Šฅ ์ถ”๊ฐ€!

์ด๋ฒˆ์—๋Š” ๋น„ํ™œ์„ฑํ™”๊ฐ€ ๊ฐ€๋Šฅํ•œ autoindex ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€๋ฅผ ํ•ด๋ณธ๋‹ค.

cmd ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋น„ํ™œ์„ฑํ™” ํ•˜๋„๋ก ๋งŒ๋“ค์–ด ๋ณธ๋‹ค.

์ผ๋‹จ server.sh ํŒŒ์ผ์„ ์ž‘์„ฑ์„ ํ•˜๊ณ  ENTRYPOINT ๋กœ ์„ค์ •์„ ํ•œ๋‹ค.

#!/bin/bash

/bin/bash -C /setup_autoindex.sh $1

service nginx start

if [ $? -eq 0 ]; then
	tail -f /var/log/nginx/access.log /var/log/nginx/error.log
f

๊ทธ๋ฆฌ๊ณ  setup_autoindex.sh ์—๊ฒŒ ์ฒซ๋ฒˆ์งธ ์ธ์ž๋ฅผ ๊ฐ™์ด ์ „๋‹ฌํ•˜์—ฌ cmd ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•œ๋‹ค.

#!/bin/bash

# setup index.html
if [ -e "/var/www/html/index.nginx-debian.html" ]; then
	mv /var/www/html/index.nginx-debian.html /var/www/html/index.html
fi

if [ "$1" == "autoindex" ]; then
	echo "autoindex on!"
	sed -i "s@autoindex off;@autoindex on;@g" /etc/nginx/sites-available/default
	sed -i "s@index index.html index.htm;@index index.htm;@g" /etc/nginx/sites-available/default
else
	echo "autoindex off!"
	sed -i "s@autoindex on;@autoindex off;@g" /etc/nginx/sites-available/default
	sed -i "s@index index.htm;@index index.html index.htm;@g" /etc/nginx/sites-available/default
fi

์ด์ œ ๋นŒ๋“œ๋ฅผ ํ•˜๊ณ  run ๋ฅผ ๋™์ž‘ ํ•  ๋•Œ autoindex cmd๋ฅผ ๊ฐ™์ด ๋ณด๋ƒˆ์„ ๋–„์— ๋Œ€ํ•ด์„œ ์ œ๋Œ€๋กœ ๋™์ž‘ ํ•˜๋Š”์ง€๋ฅผ ํ™•์ธ ํ•ด๋ณธ๋‹ค.

$ docker run --rm -it --env AUTO_INDEX=true -p 443:443 -p 80:80 --name ft_server ft_server:v3 autoindex

image-20201201012220274

image-20201201012247664

๐Ÿ“ฆ mysqlDB(maria DB) ์„ค์น˜ ๋ฐ ์„ค์ • ํ•˜๊ธฐ!

์ด๋ฒˆ์—๋Š” wordpress๋ฅผ ์œ„ํ•œ DB๋ฅผ ์„ค์ •ํ•ด ๋ณธ๋‹ค.

apt install marinade-server ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์„ค์น˜๋ฅผ ํ•œ๋‹ค.

์—ฌ๊ธฐ์„œ mariadb๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๊ธฐ์กด mysql์ด Oracle๋กœ ์ธ์ˆ˜๊ฐ€ ๋˜๋ฉด์„œ Fork๋˜์–ด ์ง„ํ–‰๋˜๊ณ  ์žˆ๋Š” opensource ํ”„๋กœ์ ํŠธ ์ด๋‹ค. (mysql๊ณผ ๋™์ผํ•œ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜์—ฌ ๋Œ€๋ถ€๋ถ„์˜ ์ž‘์—…์ด ํ˜ธํ™˜์ด ๋œ๋‹ค.)

Maria db๋ฅผ php์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ชจ๋“ˆ์ด ํ•„์š”ํ•œ๋ฐ ์ด์— ๋”ฐ๋ฅธ ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•œ๋‹ค.

$ apt install php-mysql php-mbstring
  • php-mysql : php์—์„œ mysql๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ชจ๋“ˆ
  • php-mbstring : ํ•œ๊ตญ์–ด, ์ค‘๊ตญ์–ด, ์ผ๋ณธ์–ด์™€ ๊ฐ™์€ multibyte ๋ฌธ์ž์—ด์„ ์ฒ˜๋ฆฌ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“ˆ

์ด์ œ mysql service ๋ฅผ ์‹œ์ž‘์‹œํ‚ค๊ณ  SQL ๋ช…๋ น์–ด์— ๋Œ€ํ•ด์„œ ์ž‘์„ฑ์„ ํ•ด๋ณธ๋‹ค.

# wordpress db ์ƒ์„ฑ
CREATE DATABASE wordpress;
# wordpress db๋ฅผ ์‚ฌ์šฉ
USE wordpress;
# jaeskim user๋ฅผ password `testpassword`์œผ๋กœ ๋งŒ๋“ค๊ณ  localhost์—์„œ๋งŒ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•จ.
CREATE USER 'jaeskim'@'localhost' IDENTIFIED BY 'testpassword';
# jaeskim์—๊ฒŒ wordpress db์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ ์ „๋ถ€ ์œ„์ž„
GRANT ALL PRIVILEGES ON wordpress.* TO 'jaeskim'@'localhost' WITH GRANT OPTION;
# ๊ถŒํ•œ ์„ค์ • ์—…๋ฐ์ดํŠธ
FLUSH PRIVILEGES;

์ด์ œ ์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ์‹ค์ œ dockerfile์— ์ ์šฉ์„ ํ•ด๋ณธ๋‹ค.

์ด๋•Œ dbname, dbuser, db_password์— ๋Œ€ํ•œ ํ•ญ๋ชฉ์€ ARG ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ด€๋ฆฌ๋ฅผ ํ•œ๋‹ค. (์‹ค์ œ๋กœ ์•”ํ˜ธ์™€ ๊ฐ™์€ ์ค‘์š” ์ •๋ณด๋Š” docker secret ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๊ถŒ์žฅ๋จ.)

# init arg
ARG WP_DB_NAME=wordpress
ARG WP_DB_USER=jaeskim
ARG WP_DB_PASSWORD=42seoul

# setup mysqlDB(mariaDB)
RUN service mysql start; \
	mysql -e "CREATE DATABASE ${WP_DB_NAME};\
	USE ${WP_DB_NAME}; \
	CREATE USER '${WP_DB_USER}'@'localhost' IDENTIFIED BY '${WP_DB_PASSWORD}'; \
	GRANT ALL PRIVILEGES ON ${WP_DB_NAME}.* TO '${WP_DB_USER}'@'localhost' WITH GRANT OPTION; \
	FLUSH PRIVILEGES;"

์œ„์™€ ๊ฐ™์ด mysql -e ์™€ ARG ๋ฅผ ์ด์šฉํ•˜์—ฌ mysql ์„œ๋น„์Šค ๋ถ€๋ถ„์„ ์™„์„ฑํ•˜์˜€๋‹ค.

๐Ÿ“š wordpress ์„œ๋น„์Šค ์„ค์น˜ ๋ฐ ์„ค์ •ํ•˜๊ธฐ!

์ด์ „์— ์„ค์น˜ํ•œ curl ๋ฅผ ์ด์šฉํ•˜์—ฌ https://wordpress.org/latest.tar.gz ๋ฅผ ๋‹ค์šด ๋ฐ›์•„์„œ ์„ค์น˜๋ฅผ ํ•ด๋ณธ๋‹ค!!!

์ผ๋‹จ wordpress๋ฅผ ์„ค์น˜ ํ•˜๊ธฐ ์ „์— nignix์—์„œ php๋ฅผ ๋™์ž‘ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€ ์ฃผ๋Š” ๋ชจ๋“ˆ์ธ php-fpm ๋ฅผ ์„ค์น˜ ํ•˜์—ฌ ์‚ฌ์šฉ์„ ํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  niginx/sites-available/default ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์—ฌ์„œ php๊ฐ€ ๋™์ž‘ ํ•˜๋„๋ก ์ˆ˜์ •์„ ํ•œ๋‹ค.

index index.html index.htm index.php;

location ~ \.php$ {
	include snippets/fastcgi-php.conf;
	fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}

์ด์ œ ๊ธฐ๋ณธ์ ์ธ ์ค€๋น„๊ฐ€ ๋๋‚ฌ์œผ๋‹ˆ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ wordpress๋ฅผ ๋‹ค์šด ๋ฐ›๊ณ  ์••์ถ•์„ ํ•ด์ œ ํ•œ๋‹ค.

$ curl -O https://wordpress.org/latest.tar.gz
# ๋‹ค์šด ํ›„ srcs๋กœ ์ด๋™์„ ์‹œ์ผœ์ค€๋‹ค.
$ tar -xzf latest.tar.gz -C /var/www/html/

์ด์ œ ๋‚ด๋ถ€์— ์กด์žฌํ•˜๋Š” wp-config-sample.php sed ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ ์ˆ˜์ •์„ ํ•ด๋ณธ๋‹ค.

image-20201201190619006

๋‚ด๋ถ€๋ฅผ ๋ณด๊ฒŒ ๋˜๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ ์ •์˜ ํ•ด์•ผ ํ•˜๋Š” DB ์ •๋ณด๊ฐ€ ์žˆ๋Š”๋ฐ ์ด ๋ถ€๋ถ„์„ ์•„๊นŒ์ „์— mysql๋ฅผ ์„ค์ • ํ•˜๋ฉด์„œ ์‚ฌ์šฉ ํ•˜์˜€๋˜ ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ˆ˜์ •์„ ํ•˜๋„๋ก ํ•œ๋‹ค.!

RUN mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php; \
	sed -i "s/database_name_here/${WP_DB_NAME}/g" /var/www/html/wordpress/wp-config.php; \
	sed -i "s/username_here/${WP_DB_USER}/g" /var/www/html/wordpress/wp-config.php; \
	sed -i "s/password_here/${WP_DB_PASSWORD}/g" /var/www/html/wordpress/wp-config.php

๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ key, salt ๊ฐ’์„ ์ •์˜ ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๋Š”๋ฐ ์ด๊ฒƒ์„ /dev/null ๋ฅผ ์ด์šฉํ•˜์—ฌ์„œ ์ฑ„์›Œ์ค€๋‹ค.

image-20201201192914636

wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'AUTH_KEY',         'put your unique phrase here' );/define( 'AUTH_KEY', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );/define( 'SECURE_AUTH_KEY', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'LOGGED_IN_KEY',    'put your unique phrase here' );/define( 'LOGGED_IN_KEY', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'NONCE_KEY',        'put your unique phrase here' );/define( 'NONCE_KEY', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'AUTH_SALT',        'put your unique phrase here' );/define( 'AUTH_SALT', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );/define( 'SECURE_AUTH_SALT', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'LOGGED_IN_SALT',   'put your unique phrase here' );/define( 'LOGGED_IN_SALT', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	wp_salt=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s/define( 'NONCE_SALT',       'put your unique phrase here' );/define( 'NONCE_SALT', '$wp_salt' );/g" /var/www/html/wordpress/wp-config.php; \
	unset wp_salt

์ด์ œ ์ €๋ฒˆ์— ์ž‘์„ฑํ•œ src/server.sh ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์—ฌ์„œ mysql, php-fpm ๋“ฑ๋„ ๊ฐ™์ด ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ์„ค์ •์„ ํ•œ๋‹ค.

#!/bin/bash

/bin/bash -C /setup_autoindex.sh $1

service mysql start
service php7.3-fpm start
service nginx start

if [ $? -eq 0 ]; then
	tail -f /var/log/nginx/access.log /var/log/nginx/error.log
fi

์ด์ œ dockerfile๋กœ ์ •๋ฆฌํ•˜์—ฌ์„œ ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•ด ๋ณธ๋‹ค.!

$ docker run --rm -it -p 443:443 -p 80:80 --name ft_server ft_server

https://localhost/wordpress ๋กœ ์ ‘๊ทผ์„ ํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด wordpress๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์˜ฌ๋ผ์˜จ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

image-20201201193659307

๐Ÿง‘โ€๐Ÿ’ป phpmyadmin ์„ค์น˜ ํ•˜๊ธฐ!

์ด์ œ ๋งˆ์ง€๋ง‰์œผ๋กœ db๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ phpmyadmin ๋ฅผ ์„ค์น˜ ํ•ด๋ณธ๋‹ค.

Curl ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ผ๋‹จ phpmyadmin๋ฅผ ๋‹ค์šด ๋ฐ›๋Š”๋‹ค.

RUN curl -O https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.tar.gz

๊ทธ๋ฆฌ๊ณ  ์ด์ œ ์••์ถ•์„ ํ•ด์ œํ•˜๊ณ  ์ƒ์„ฑ๋œ ํด๋”์˜ ์ด๋ฆ„์„ ์ˆ˜์ •ํ•ด์ค€ ํ›„ config.sample.inc.php ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค์ •์„ ํ•ด๋ณธ๋‹ค.

์—ฌ๊ธฐ์„œ๋Š” blowfish_secret ๋ผ๋Š” cookie๋ฅผ ์•”ํ˜ธํ™” ํ•˜๊ฒŒ ๋˜๋Š” ํ‚ค๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋„ฃ์–ด์ฃผ๊ฒŒ ๋œ๋‹ค.

blowfish_secret=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#\%+=' | fold -w 64 | sed 1q); \
	sed -i "s@''; /\* YOU MUST FILL IN THIS FOR COOKIE AUTH! \*/@'$blowfish_secret';@g" /var/www/html/phpmyadmin/config.inc.php; \
	unset blowfish_secret;

๊ทธ๋ฆฌ๊ณ  ๋งˆ์ง€๋ง‰์œผ๋กœ ํ˜„์žฌ /var/www/html ์ด root ์†Œ์œ ์ž๋กœ ๋“ฑ๋ก์ด ๋˜์–ด ์žˆ์–ด์„œ phpmyadmin ์—์„œ temp directory๋ฅผ ์ƒ์„ฑ์„ ๋ชปํ•œ๋Š” ์ด์Šˆ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ถŒํ•œ์„ www-data:www-data ๋กœ ์ˆ˜์ •์„ ํ•ด์ค€๋‹ค.

image-20201201194547831

์ด์ œ ์ ‘๊ทผ์„ ํ•˜๊ฒŒ ๋˜๋ฉด ์œ„์—์„œ ๋งŒ๋“ค์—ˆ๋˜ ๊ณ„์ •์„ ํ†ตํ•ด์„œ ๋กœ๊ทธ์ธ์ด ๊ฐ€๋Šฅ ํ•œ ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.


42Seoul ์—์„œ ์ง„ํ–‰ํ•œ ft_server ํ”„๋กœ์ ํŠธ๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€ ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ง„ํ–‰๋œ Dockerfile๊ณผ src ํŒŒ์ผ์€ ์•„๋ž˜์˜ github์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.!

jaeseokim/42cursus/02ftserver

Buy me a coffeeBuy me a coffee
Written by

@JaeSeoKim

๋ณด์•ˆ๊ณผ ๊ฐœ๋ฐœ์„ ์ข‹์•„ํ•˜๋Š” ํ•™์ƒ ์ž…๋‹ˆ๋‹ค~!