Command Explanation
FROM 어떤 이미지를 기반으로 생성할 것인지 결정한다
It generate image base on other image
MAINTAINER 이미지를 생성한 사람의 정보를 설정한다
It is information of person who created image
RUN 이미지가 생성될때 스크립트 혹은 명령을 실행합니다
When a image is created, it run shell script or command
CMD 컨테이너가 시작되었을 때 스크립트 혹은 명령을 실행합니다
It run shell script or command after starting container
ENTRYPOINT 컨테이너가 시작되었을 때 스크립트 혹은 명령을 실행하고
뒤에 CMD가 올 경우 CMD의 내용을 매개변수로 받게 된다
It run shell script or command after starting container.
When CMD comes after it, it get parameter from CMD attributes
EXPOSE 호스트와 연결할 포트번호를 설정한다
It set port number for connecting to host
ENV 환경변수를 설정하며 RUN, CMD, ENTRYPOINT에 적용된다
It set environment variables for RUN,CMD, ENTRYPOINT
ADD 파일을 이미지에 추가하며 압축해제기능 및 URL사용이 가능하다
It add file into image with unzip and remote-copy
COPY 파일을 그대로 복사하여 이미지에 추가하며 URL 사용이 불가능하다
It copy file into image
VOLUME 디렉토리의 내용을 컨테이너에 저장하지 않고 호스트에 저장하도록 설정한다
It set host directory for saving files
USER 명령을 사용할 사용자 계정을 설정하며 RUN, CMD, ENTRYPOINT에 적용된다
It set user for execute RUN,CMD, and ENTRYPOINT
WORKDIR RUN, CMD, ENTRYPOINT의 명령이 실행될 디렉토리를 설정한다
It set directory for RUN,CMD and ENTRYPOINT
ONBUILD 생성한 이미지를 기반으로 다른 이미지가 생성될 때 실행한다
When other image is maked base on this image, it set trigger

example: MariaDB dockerfile

# ubuntu bionic 이미지로터 시작한다.
# make image from ubuntu:bionic image
FROM ubuntu:bionic

# mysql 사용자 계정을 생성한다
# add user and group for running service
RUN groupadd -r mysql && useradd -r -g mysql mysql

# 패키지 리스트를 업그레이드 하고 gnupg가 없으면 설치한다.
# It is updaed package list. And if gnupg is not installed it install.
RUN set -ex; apt-get update; \
	if ! which gpg; then \
		apt-get install -y --no-install-recommends gnupg; \
	fi; \
	if ! gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
		 apt-get install -y --no-install-recommends dirmngr; \
	fi; \
	rm -rf /var/lib/apt/lists/*


# GOSU_VERSION이라는 환경변수에 1.10을 설정한다.
# It set 1.10 into GOSU_VERSION.
ENV GOSU_VERSION 1.10

RUN set -ex; \
	\
	fetchDeps=' \
		ca-certificates \
		wget \
	'; \
	apt-get update; \
	apt-get install -y --no-install-recommends $fetchDeps; \
	rm -rf /var/lib/apt/lists/*; \
	\
	dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
	wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
	wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
	\
	export GNUPGHOME="$(mktemp -d)"; \
	gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
	gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
	command -v gpgconf > /dev/null && gpgconf --kill all || :; \
	rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
	\
	chmod +x /usr/local/bin/gosu; \
	gosu nobody true; \
	\
	apt-get purge -y --auto-remove $fetchDeps

RUN mkdir /docker-entrypoint-initdb.d
RUN apt-get update && apt-get install -y --no-install-recommends \
		apt-transport-https ca-certificates \
		pwgen \
		tzdata \
	&& rm -rf /var/lib/apt/lists/*

ENV GPG_KEYS \
	199369E5404BD5FC7D2FE43BCBCB082A1BB943DB \
	177F4010FE56CA3336300305F1656F24C74CD1D8 \
	430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A \
	4D1BB29D63D98E422B2113B19334A25F8507EFA5
    
RUN set -ex; \
	export GNUPGHOME="$(mktemp -d)"; \
	for key in $GPG_KEYS; do \
		gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
	done; \
	gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mariadb.gpg; \
	command -v gpgconf > /dev/null && gpgconf --kill all || :; \
	rm -r "$GNUPGHOME"; \
	apt-key list

ENV MARIADB_MAJOR 10.4
ENV MARIADB_VERSION 1:10.4.2+maria~bionic

RUN set -e;\
	echo "deb http://ftp.osuosl.org/pub/mariadb/repo/$MARIADB_MAJOR/ubuntu bionic main" > /etc/apt/sources.list.d/mariadb.list; \
	{ \
		echo 'Package: *'; \
		echo 'Pin: release o=MariaDB'; \
		echo 'Pin-Priority: 999'; \
	} > /etc/apt/preferences.d/mariadb

RUN set -ex; \
	{ \
		echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \
		echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \
	} | debconf-set-selections; \
	backupPackage='mariadb-backup'; \
	apt-get update; \
	apt-get install -y \
		"mariadb-server=$MARIADB_VERSION" \
`mysql-common` is only installed once from just mariadb repos
		$backupPackage \
		socat \
	; \
	rm -rf /var/lib/apt/lists/*; \
	sed -ri 's/^user\s/#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/*; \
	rm -rf /var/lib/mysql; \
	mkdir -p /var/lib/mysql /var/run/mysqld; \
	chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \
	chmod 777 /var/run/mysqld; \
	find /etc/mysql/ -name '*.cnf' -print0 \
		| xargs -0 grep -lZE '^(bind-address|log)' \
		| xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/'; \
	echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf

# /var/lib/mysql을 베이스 디렉토리로 변경한다.
# It change base directory to /var/lib/mysql.
VOLUME /var/lib/mysql

# docker-entrypoint.sh 을 /usr/local/bin/ 으로 복사한다.
# It copy docker-entrypoint.sh to /usr/local/bin/.
COPY docker-entrypoint.sh /usr/local/bin/

# link를 생성한다.
# It make link from usr/local/bin/docker-entrypoint.sh
RUN ln -s usr/local/bin/docker-entrypoint.sh /

# doker-entrypoint.sh 을 실행한다.
# It execute docker-entrypint.sh
ENTRYPOINT ["docker-entrypoint.sh"]

# 3306 를 docker 외부로 연결한다.
# It make port-forwarding for inbound.
EXPOSE 3306

# mysqld를 실행한다.
# It execute mysqld.
CMD ["mysqld"]