# DockerFile 을 이용하여 나만의 Docker Image 만들기

{% hint style="info" %}
**2022년 NHN Cloud&#x20;**<mark style="color:red;">**무료**</mark>**&#x20;교육일정** : <https://doc.skill.or.kr/2022-NHN-Cloud-Education>
{% endhint %}

{% hint style="warning" %}
**2022년 NHN Cloud&#x20;**<mark style="color:red;">**행사/프로모션**</mark>**&#x20;정보 공유** : <https://doc.skill.or.kr/2022-NHN-Cloud-Event-Promotion>
{% endhint %}

## 1. 먼저 알아 두기     &#x20;

### 1.1 DockerFile 이란?

> DockerFile 은 코드의 형태로 인프라를 구성하는 방법을 텍스트 형식으로 저장해 놓은 파일이며 docker build 를 사용하여 자신만의 이미지를 만들 수 있다.

### 1.2 Docker Build 란?   &#x20;

> DockerFile 및 컨텍스트로부터 이미지를 빌드하는 Docker 명령

### 1.3 Docker-Compose 란?

> Compose는 멀티 컨테이너 도커 애플리케이션을 정의하고 실행하는 도구이다. YAML 파일을 사용하여 애플리케이션의 서비스를 구성하며 하나의 명령을 가지고 모든 컨테이너의 생성 및 시작 프로세스를 수행한다.

## 2. DockerFile을 이용하여 만들어 보자!!!    &#x20;

### 2.1 서비스 설계 구성       &#x20;

|                       | DataBase Server    | WEB/WAS Service                                             |
| --------------------- | ------------------ | ----------------------------------------------------------- |
| Docker Hub Base Image | mariadb:10.4.18    | ubuntu:20.04                                                |
| OS                    | Ubuntu 20.04.2 LTS | Ubuntu 20.04.2 LTS                                          |
| Service               | Mariadb 10.4.18    | <p>Nginx 1.18.0</p><p>Tomcat 9.0.45</p>                     |
| Developer             |                    | <p>OpenJDK 1.8.x</p><p>Maven 3.8.1</p><p>NodeJS 14.16.1</p> |
| Dev Source            |                    | USE Github                                                  |
| Service Port          | 3306               | 80, 8080                                                    |

### 2.2 아키텍처 물리 설계 구성도   &#x20;

> **대규모 3-Tier 구성 : 로드 발란스를 이용하여 3-Tier 구성을 확장하는 구성 방식. 웹 시스템의 사용자가 많은 엔터프라이즈 어플리케이션일 경우 대부분 대규모 3-Tier 구성을 이용하고 있다.**

![](https://lh3.googleusercontent.com/oUpNO68tu2GvjTzWHulL3jQUx8v-dJDMlbZPwiCTWoDM7uWgzVBdnuC4OBLDJQl8i_Luyg0n9A8-cMwUXZufw3UO0teA2RKNVLSKlnJdTsOLBqutn1Jk1FHCyPr9tZZFwiQ47c6QJ-g)

### 2.3 Database(Mariadb:10.4.18) Docker Image 만들기       &#x20;

```
### Base Image 지정    
FROM mariadb:10.4.18  

### TimeZone 환경 변수 지정
ENV TZ Asia/Seoul  

### Mariadb root 비밀번호 설정
ENV MYSQL_ROOT_PASSWORD=root

### Mariadb Database 생성  
ENV MYSQL_DATABASE=deverse      

### TimeZone 설
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

### Mariadb User 및 DB 스키마 설정 스크립
ADD deverse.sql /docker-entrypoint-initdb.d/deverse.sql
ADD db_user.sql /docker-entrypoint-initdb.d/db_user.sql

### 홈 디렉토리
WORKDIR /home/dev

### 서비스 포
EXPOSE 3306
```

{% hint style="info" %}
소스 파일은 [Github ](https://github.com/bc-hwang/TEST/)에서 참고 하시기 바랍니다.
{% endhint %}

### 2.4 Nginx & Tomcat(ubuntu:20.04) Docker Image 만들기

```
### Base Image 지정
FROM ubuntu:20.04

### TimeZone 환경 변수 지정
ENV TZ Asia/Seoul

### TimeZone 설정    
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

### /home/dev 폴더 생성
RUN mkdir /home/dev

### update 및 패키지 설치     
RUN apt update && apt -y install vim git tar gzip build-essential curl alien openjdk-8-jdk nginx

### nodejs 설
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_14_setup.sh && bash nodesource_14_setup.sh && apt -y install nodejs

### build, tomcat, maven, nginx(default.conf) 파일 복사   
COPY build.tar.gz /home/dev/build.tar.gz
COPY tomcat-9.0.45.tar.gz /home/dev/tomcat-9.0.45.tar.gz
COPY apache-maven-3.8.1.tar.gz /home/dev/apache-maven-3.8.1.tar.gz
COPY default.conf /etc/nginx/conf.d/default.conf

### ubuntu01 계정 생성
RUN addgroup --gid 1100 ubuntu01 && adduser --disabled-password --home /home/dev --no-create-home --system -q --uid 1000 --ingroup ubuntu01 ubuntu01

### Github Source 파일 다운로드     
RUN git clone https://github.com/bc-hwang/TEST.git /home/dev/deverse

### /home/dev 폴더 이동   
WORKDIR /home/dev

### 암축 파일 해제    
RUN tar -zxvf apache-maven-3.8.1.tar.gz
RUN tar -zxvf tomcat-9.0.45.tar.gz
RUN tar -zxvf build.tar.gz

### maven link 설정
RUN ln -s /home/dev/apache-maven-3.8.1/bin/mvn /usr/bin/mvn

### Build 실행
RUN cd /home/dev/build && bash ./back_build.sh
RUN cd /home/dev/build && bash ./front_build.sh

### Nginx & Tomcat Service 실행    
CMD nginx -g 'daemon on;' && /home/dev/tomcat-9.0.45/bin/catalina.sh run

### 서비스 포
EXPOSE 80 8080

```

{% hint style="info" %}
소스 파일은 [Github ](https://github.com/bc-hwang/TEST/)에서 참고 하시기 바랍니다.
{% endhint %}

### 2.5 DockerFile Buil 하기 후 Docker Hub 에 업로드 하기     &#x20;

{% tabs %}
{% tab title="Database(mariadb:10.4.18)" %}
**Step1. docker loign** <br>

**Step2. 작성 한 DockerFile 에서 빌드 하기**

&#x20; **• docker build -t tomcat\_mariadb:mariadb .**

&#x20; **• docker images ## 로컬에 저장된 Docker Images 확인**<br>

**Step3. 로컬에 만든 이미지 실행 및 확인**

&#x20; **• docker run –d tomcat\_mariadb:mariadb** <br>

**Step4. Docker Hub 이미지 업로드**

&#x20; **• docker tag tomcat\_mariadb:mariadb bchwang/tomcat\_mariadb:mariadb**

&#x20; **• docker push bchwang/tomcat\_mariadb:mariadb**  <br>

**Step5. Docker Hub 에 등록된 이미지 확인**

&#x20; **• Docker Hub 에 개인 개정으로 로그인 후 Docker Image 및 Tag 확인**
{% endtab %}

{% tab title="Nginx\&Tomcat(ubuntu:20.04)" %}
**Step1. docker loign** <br>

**Step2. 작성 한 DockerFile 에서 빌드 하기**

&#x20; **• docker build -t tomcat\_mariadb:nginx\_tomcat .**

&#x20; **• docker images ## 로컬에 저장된 Docker Images 확인**<br>

**Step3. 로컬에 만든 이미지 실행 및 확인**

&#x20; **• docker run –d –p 80:80 tomcat\_mariadb: nginx\_tomcat** <br>

**Step4. Docker Hub 이미지 업로드**

&#x20; **• docker tag tomcat\_mariadb:nginx\_tomcat bchwang/tomcat\_mariadb:nginx\_tomcat**&#x20;

&#x20; **• docker push bchwang/tomcat\_mariadb: nginx\_tomcat** <br>

**Step5. Docker Hub 에 등록된 이미지 확인**

&#x20; **• Docker Hub 에 개인 개정으로 로그인 후 Docker Image 및 Tag 확인**<br>
{% endtab %}
{% endtabs %}

### 2.6 Docker-Compose 를 이용하여 실행 하기     &#x20;

#### 2.6.1 Local 에서 Build Image 를 이용하여 docker-compose.yml 만들기      &#x20;

{% code title="docker-compose.yml" %}

```
### 빌드할 버전    
version: '2'

### 서비스 설정    
services:
  mariadb:
    image: tomcat_mariadb:mariadb
    restart: always

  nginx-tomcat:
    image: tomcat_mariadb:nginx_tomcat
    restart: always
    ports:
      - 80:80
    links:
      - mariadb
```

{% endcode %}

{% hint style="info" %}
소스 파일은 [Github ](https://github.com/bc-hwang/TEST/)에서 참고 하시기 바랍니다.
{% endhint %}

#### 2.6.2 Docker Hub Image 를 이용하여 docker-compose.yml 만들기    &#x20;

{% code title="docker-compose.yml" %}

```
### 빌드할 버전    
version: '2'

### 서비스 설정    
services:
  mariadb:
    image: bchwang/tomcat_mariadb:mariadb
    restart: always

  nginx-tomcat:
    image: bchwang/tomcat_mariadb:nginx_tomcat
    restart: always
    ports:
      - 80:80
    links:
      - mariadb
```

{% endcode %}

## 3. NHN Cloud 를 이용한 Kubernetes 서비스를 구축 방법     &#x20;

### 3.1 커뮤니티 블로그 서비스 Yaml 설정 하기         &#x20;

> NHN Cloud 를 이용하여 커뮤니티 블로그 서비스를 Kubernetes 로 구축 하는 방법을 소개해 드립니다.
>
> 아래의 내용을 따라 하시거나 [GitHub ](https://github.com/bc-hwang/TEST)의 소스 파일을 참고 시기 바랍니다.

### 3.2 NameSpace Yaml        &#x20;

```
apiVersion: v1
kind: Namespace
metadata:
  name: project
```

### 3.3 Mariadb Yaml    &#x20;

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-mariadb
  labels:
    app: mariadb
  namespace: project
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      hostname: mariadb
      containers:
      - name: mariadb
        image: bchwang/tomcat_mariadb:mariadb
        ports:
        - containerPort: 3306
          name: mariadb
```

### 3.4. Mariadb Service Yaml     &#x20;

```
apiVersion: v1
kind: Service
metadata:
  name: tomcat-mariadb
  labels:
    app: mariadb
  namespace: project
spec:
  clusterIP: None
  ports:
  - port: 3306
  selector:
    app: mariadb
```

### 3.5 Nginx & Tomcat Service Yaml   &#x20;

```
apiVersion: v1
kind: Service
metadata:
  name: nginx-tomcat
  labels:
    app: nginx-tomcat
  namespace: project
  ## 오브젝트 선언형 관리
  annotations
    ## Floating ip 유지 설정
    loadbalancer.openstack.org/keep-floatingip: "true"
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 30000
  selector:
    app: nginx-tomcat
  ## NodePort 가 아니라 LoadBalancer 로 설정 해 주어야 함.
  type: LoadBalancer
  ## Floating ip 를 지정 하여 Loadbalancer ip 로 설정.
  loadBalancerIP: 133.186.216.107
```

### 3.6 Nginx & Tomcat Yaml    &#x20;

> 아래의 내용 중 hostAliases 의 ip 정보가 mariadb 의 IP 정보를 입력 하여야 함.
>
> Mariadb 를 실행 한 후에 `kuberctl get pod -n project` 로 나온 IP 값을 입력 하면 됨.

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-tomcat
  labels:
    app: nginx-tomcat
  namespace: project
spec:
  replicas: 10
  selector:
    matchLabels:
      app: nginx-tomcat
  template:
    metadata:
      labels:
        app: nginx-tomcat
      name: nginx-tomcat
    spec:
      hostname: nginx-tomcat
      hostAliases:
      - ip: "10.100.4.9" ### mariadb hosts 지정
        hostnames:
        - "mariadb"
      containers:
      - name: nginx-tomcat
        image: bchwang/tomcat_mariadb:nginx_tomcat
        ports:
        - containerPort: 80
          name: nginx-tomcat
```

{% hint style="info" %}
소스 파일은 [Github ](https://github.com/bc-hwang/TEST/)에서 참고 하시기 바랍니다.
{% endhint %}

### 3.7 커뮤니티 블로그 서비스 Yaml 실행 하기  &#x20;

{% code title="NHN Cloud Manager Server 에 접속 하여 실행 함" %}

```
### mariadb 및 서비스 실행   
$ kubectl apply -f 1.kubernetes_mariadb+service.yaml

### Mariadb Pod 실행 및 IP 정보 확인     
$ kubectl get pod -n project -o wide
NAME                                        READY     STATUS    RESTARTS   AGE          IP            NODE       NOMINATED NODE   READINESS GATES
mariadb-service-59868b7dd6-xb8tq            1/1       Running   0          1m           10.100.4.9    kubernetes   <none>           <none>

### ip 입력 후 nginx & tomcat 실행    
kubectl apply -f 2.kubernetes_nginx+tomcat.yaml

### Pod 실행 및 IP 정보 확인     
$ kubectl get pod -n project -o wide
NAME                                        READY     STATUS    RESTARTS   AGE          IP            NODE       NOMINATED NODE   READINESS GATES
mariadb-service-59868b7dd6-xb8tq            1/1       Running   0          1m           10.100.4.9    kubernetes   <none>           <none>
nginx_tomcat-service-59868b7dd6-xb8tq       1/1       Running   0          1m           10.100.4.10   kubernetes   <none>           <none>

### Service 정보 확인     
$ kubectl get service -n project -o wide
NAMESPACE              NAME                            TYPE         CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE     SELECTOR
nginx_tomcat           nginx_tomcat                    LoadBalancer 133.186.216.107 <none>        80/TCP                   8m4s    app=nginx_tomcat
mariadb                mariadb                         ClusterIP    <none>          <none>        3306/TCP                 18m4s   app=mariadb
```

{% endcode %}

### 3.8 공인 IP로 접속 한 화면    &#x20;

![](/files/-Md0TjX4Oncq0KSKcMQm)

## 4. GitHub 정보 및 커뮤니티 블로그 소개     &#x20;

### 4.1 개발 환경

* Ubuntu/20.x (OS)
* mariadb/10.4.18 (DB Service)
* tomcat/9.0.45 (WAS Service)
* nginx/1.18.0 (WEB Service)
* OpenJDK/1.8.x
* Maven/3.8.1
* NodeJS/14.6.1

### 4.2 NHN Cloud Kubernetes & Docker 사용해 보기

#### A. DockerFile 을 이용하여 Docker Images 만들기(Tomcat, Mariadb)

* **Dockerfile 을 이용하여 Mariadb 이미지 만들기**

```
   - /install/mariadb/db_user.sql (DB 계정 스크립트)
   - /install/mariadb/devers.sql (DB 스키마 스크립트)
   - /install/mariadb/dockerfile (Docker Image 스크립트)
```

* **Dockerfile Build 방법(mariadb Image)**

```
   - /install/mariadb 의 폴더에 dockerfile 을 확인 후 아래 명령어 실행
     -> docker build -t tomcat_mariadb:mariadb .
   - docker images (tomcat_mariadb:mariadb 이미지 확인)
```

* **Dockerfile 을 이용하여 nginx\_tomcat 이미지 만들기**

```
   - /install/nginx_tomcat/apache-maven-3.8.1.tar.gz (maven src 파일)
   - /install/nginx_tomcat/tomcat-9.0.45.tar.gz (tomcat src 파일)
   - /install/nginx_tomcat/build.tar.gz (src build 파일)
   - /install/nginx_tomcat/dockerfile (Docker Image 스크립트)
   - /install/nginx_tomcat/default.conf (nginx 설정 파일)
   - /install/nginx_tomcat/nginx.conf (nginx 설정 파일)
```

* **Dockerfile Build 하는 방법(nginx\_tomcat Image)**

```
   - /install/nginx_tomcat 의 폴더에 dockerfile 을 혹인 후 아래 명령어 실행
     -> docker build -t tomcat_mariadb:nginx_tomcat .
   - docker images (tomcat_mariadb:nginx_tomcat 이미지 확인)
```

* **Docker Hub push 하는 방법**

```
   - docker login 을 함.
   - docker tag tomcat_mariadb:nginx_tomcat bchwang/tomcat_mariadb:nginx_tomcat (tag 설정)
   - docker tag tomcat_mariadb:mariadb bchwang/tomcat_mariadb:mariadb (tag 설정)
   - docker push bchwang/tomcat_mariadb:nginx_tomcat (docker hub 에 업로드 진행)
   - docker push bchwang/tomcat_mariadb:mariadb (docker hub 에 업로드 진행)
```

### B. Build 된 Tomcat, Mariadb Images 실행 하기

* **docker images 확인 하기**

```
   - docker images
```

* **Local Image 로 실행 하기**

```
   - docker run -d --name mariadb tomcat_mariadb:mariadb
   - docker run -d --name tomcat -p 80:80 --link mariadb tomcat_mariadb:nginx_tomcat
```

* **docker Hub Image 로 실행 하기**

```
   - docker run -d --name mariadb bchwang/tomcat_mariadb:mariadb
   - docker run -d --name tomcat -p 80:80 --link mariadb bchwang/tomcat_mariadb:nginx_tomcat
```

### C. Docker-Compose 사용하기

* **Local Images 로 실행 하기**

```
   - /install/docker-compose_local.yml (docker-compose 설정 값 Local Images 사용)
```

* **Docker Hub 에 Push 한 Images 로 실행 하기**

```
   - /install/docker-compose.yml (docker-compose 설정 값 Docker Hub Images 사용)
```

### D. NHN Cloud Kubernetes 로 사용하기

* **NHN Cloud 회원 가입 및 Console 로그인 : <http://toast.com>**
* **NHN Cloud Console 에 Kubernetes Manager Instance 생성**

```
   - NHN Cloud Console 접속 -> Compute -> Instance -> 인스턴스 생성
   - 이미지(Ubuntu Server 20.04 LTS) -> 인스턴스 이름(kube-manager) -> 인스턴스 타입(Standard : t2.c1m1) -> 키 페어 선택(생성 or 기존에 사용하던것)
     -> 블록 스토리지 타입(HDD or SDD) -> 블록 스토리지 크기(50~100GB) -> 인스턴스 생성
```

* **NHN Cloud Console 에서 Kubernetes 생성**

```
   - NHN Cloud Console 접속 -> Container -> Kubernetes -> 클러스터 생성
   - 클러스터 이름(kube-master) -> 인스턴스 타입(Standard : m2.c8m16) -> 노드 수(2~3개) -> 키 페어 선택(생성 or 기존에 사용하던것)
     -> 블록 스토리지 타입(HDD or SDD) -> 블록 스토리지 크기(50~100GB) -> 오토 스케일러(사용 or 사용 안 함) -> 클러스터 생성
```

* **NHN Cloud Console 에서 SSH 접속 설정**

```
   - NHN Cloud Console 접속 -> Network -> Security Groups -> Default 선택 -> 보안정책 생성 -> 포트: 22, 원격 공인IP 입력(ex 포트: 22, CIDR: 111.111.111.111/32) 후 확인
   - 자세한 사항은 https://docs.toast.com/ko/Compute/Instance/ko/overview/#linux (SSH 접속 방법) 참고
```

* **NHN Cloud 에서 생성된 Instance(Kube-manager) 접속 방법 및 Kubernetes 연결 방법**

```
   - https://doc.skill.or.kr/nhn-cloud#5-2-kube-manager-api 에서 NHN Cloud Kubernetes API 설정 방법
```

* **NHN Cloud 에서 Kubernetes 를 이용하여 서비스 사용하기**

```
   - /install/1.kubernetes_mariadb+service.yaml (mariadb Pod/Service 등 설정 값)
     -> kubectl apply -f 1.kubernetes_mariadb+service.yaml (mariadb pod 와 Service 실행) -> kubectl get pod -n project -o wide (Mariadb IP 확인)
   - /install/2.kubernetes_nginx+tomcat.yaml (tomcat Pod 설정 값)
     -> vi 2.kubernetes_nginx+tomcat.yaml (- ip: "10.100.4.9" 의 값을 Mariadb IP 로 수정) -> kubectl apply -f 2.kubernetes_nginx+tomcat.yaml (Nginx 와 Tomcat Pod 실행) 
   - Build 설정 파일
     - nginx+tomcat Server 접속
     - /home/dev/build/application.yml 에 DB 접속 정보 설정
     - /home/dev/deverse/frontend/.env.build 에 url 접속 정보 설정
```

## TIPs.1 DockerFile 기본 형식 자세히 알아 보기   &#x20;

### TIPs 1.1 DockerFile 기본 형식    &#x20;

| Command    | Description |
| ---------- | ----------- |
| FROM       | 베이스 이미지 지정  |
| RUN        | 명령어 실행      |
| CMD        | 데몬 실행       |
| LABEL      | 라벨 설정       |
| EXPOSE     | 포트 설정       |
| ENV        | 환경 변수 설정    |
| ADD        | 파일 추가       |
| COPY       | 파일 복사       |
| USER       | 사용자 설정      |
| WORKDIR    | 작업 디렉토리 지정  |
| VOLUME     | 볼륨 마운트      |
| ENTRYPOINT | 데몬 실행       |
| ONBUILD    | 빌드 후 실행 명   |

### TIPs 1.2 Docker Build 기본 형식    &#x20;

| Name, Shorthand         | Default | Description                                                                                       |
| ----------------------- | ------- | ------------------------------------------------------------------------------------------------- |
| --add-host              |         | Add a custom host-to-IP mapping (host:ip)                                                         |
| --build-arg             |         | Set build-time variables                                                                          |
| --cache-from            |         | Images to consider as cache sources                                                               |
| --cgroup-parent         |         | Optional parent cgroup for the container                                                          |
| --compress              |         | Compress the build context using gzip                                                             |
| --cpu-period            |         | Limit the CPU CFS (Completely Fair Scheduler) period                                              |
| --cpu-quota             |         | Limit the CPU CFS (Completely Fair Scheduler) quota                                               |
| --cpu-shares , -c       |         | CPU shares (relative weight)                                                                      |
| --cpuset-cpus           |         | CPUs in which to allow execution (0-3, 0,1)                                                       |
| --cpuset-mems           |         | MEMs in which to allow execution (0-3, 0,1)                                                       |
| --disable-content-trust | true    | Skip image verification                                                                           |
| --file , -f             |         | Name of the Dockerfile (Default is ‘PATH/Dockerfile’)                                             |
| --force-rm              |         | Always remove intermediate containers                                                             |
| --iidfile               |         | Write the image ID to the file                                                                    |
| --isolation             |         | Container isolation technology                                                                    |
| --label                 |         | Set metadata for an image                                                                         |
| --memory , -m           |         | Memory limit                                                                                      |
| --memory-swap           |         | Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap                               |
| --network               |         | <p> API 1.25+</p><p>Set the networking mode for the RUN instructions during build</p>             |
| --no-cache              |         | Do not use cache when building the image                                                          |
| --platform              |         | <p> experimental (daemon)API 1.32+</p><p>Set platform if server is multi-platform capable</p>     |
| --pull                  |         | Always attempt to pull a newer version of the image                                               |
| --quiet , -q            |         | Suppress the build output and print image ID on success                                           |
| --rm                    | true    | Remove intermediate containers after a successful build                                           |
| --security-opt          |         | Security options                                                                                  |
| --shm-size              |         | Size of /dev/shm                                                                                  |
| --squash                |         | <p> experimental (daemon)API 1.25+</p><p>Squash newly built layers into a single new layer</p>    |
| --stream                |         | <p> experimental (daemon)API 1.31+</p><p>Stream attaches to server to negotiate build context</p> |
| --tag , -t              |         | Name and optionally a tag in the ‘name:tag’ format                                                |
| --target                |         | Set the target build stage to build.                                                              |
| --ulimit                |         | Ulimit options                                                                                    |

### TIPs 1.3 Docker-Compose 기본 형식

| Command | Description                              |
| ------- | ---------------------------------------- |
| build   | Build or rebuild services                |
| config  | Validate and view the Compose file       |
| create  | Create services                          |
| down    | Stop and remove resources                |
| events  | Receive real time events from containers |
| exec    | Execute a command in a running container |
| help    | Get help on a command                    |
| images  | List images                              |
| kill    | Kill containers                          |
| logs    | View output from containers              |
| pause   | Pause services                           |
| port    | Print the public port for a port binding |
| ps      | List containers                          |
| pull    | Pull service images                      |
| push    | Push service images                      |
| restart | Restart services                         |
| rm      | Remove stopped containers                |
| run     | Run a one-off command                    |
| scale   | Set number of containers for a service   |
| start   | Start services                           |
| stop    | Stop services                            |
| top     | Display the running processes            |
| unpause | Unpause services                         |
| up      | Create and start containers              |
| version | Show version information and quit        |

| Name, Shorthand              | Description                                                                                                    |
| ---------------------------- | -------------------------------------------------------------------------------------------------------------- |
| -f, --file FILE              | <p>Specify an alternate compose file<br>(default: docker-compose.yml)</p>                                      |
| -p, --project-name NAME      | <p>Specify an alternate project name <br>(default: directory name)</p>                                         |
| --profile NAME               | Specify a profile to enable                                                                                    |
| -c, --context NAME           | Specify a context name                                                                                         |
| --verbose                    | Show more output                                                                                               |
| --log-level LEVEL            | Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)                                                          |
| --ansi (never\|always\|auto) | Control when to print ANSI control characters                                                                  |
| --no-ansi                    | Do not print ANSI control characters (DEPRECATED)                                                              |
| -v, --version                | Print version and exit                                                                                         |
| -H, --host HOST              | Daemon socket to connect to                                                                                    |
| --tls                        | Use TLS; implied by --tlsverify                                                                                |
| --tlscacert CA\_PATH         | Trust certs signed only by this CA                                                                             |
| --tlscert CLIENT\_CERT\_PATH | Path to TLS certificate file                                                                                   |
| --tlskey TLS\_KEY\_PATH      | Path to TLS key file                                                                                           |
| --tlsverify                  | Use TLS and verify the remote                                                                                  |
| --skip-hostname-check        | Don't check the daemon's hostname against the name specified in the client certificate                         |
| --project-directory PATH     | <p>Specify an alternate working directory <br>(default: the path of the Compose file)</p>                      |
| --compatibility              | <p>If set, Compose will attempt to convert keys <br>in v3 files to their non-Swarm equivalent (DEPRECATED)</p> |
| --env-file PATH              | Specify an alternate environment file                                                                          |

{% hint style="info" %}
**2022년 NHN Cloud&#x20;**<mark style="color:red;">**무료**</mark>**&#x20;교육일정** : <https://doc.skill.or.kr/2022-NHN-Cloud-Education>
{% endhint %}

{% hint style="warning" %}
**2022년 NHN Cloud&#x20;**<mark style="color:red;">**행사/프로모션**</mark>**&#x20;정보 공유** : <https://doc.skill.or.kr/2022-NHN-Cloud-Event-Promotion>
{% endhint %}

{% embed url="<https://paypal.me/shop2002>" %}
donation
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.skill.or.kr/dockerfile-docker-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
