# Docker 範本 ## Dockerfile ``` dockerfile FROM ubuntu:20.04 MAINTAINER meow # update package record RUN apt update # 安裝基本的工具 RUN apt -y install vim \ git # 安裝執行 php 相關的 package RUN apt -y install <redacted> ``` 建置環境:將 Dockerfile 放到一個空的資料夾中 ``` shell docker build -t <name> . # 根據當前目錄的 dockerfile 進行建置 ``` ## docker-compose.yml ``` yaml version: '2' services: my_website: container_name: meowwww # container name image: ubuntu:meow # build image name build: . # 他會去找有沒有 ubuntu:meow 這個 image,沒有的話就從當前目錄的 Dockerfile 建立此 image volume: ./<path>:/var/www/html # 將 <path> 此 directory map 到 container 的 /var/www/html 資料夾 restart: on-failure # exit code 代表有 on-failure error 就會重新啟動 ports: - '1234:80' # host 的 1234 port 會對到 container 的 80 port ``` 建置環境:安裝 docker-compose,並且建立檔案名稱為 docker-compose.yml 的檔案,將上方的 rule 寫到裡面 ``` shell sudo apt install -y docker-compose docker-compose build # build image docker-compose up # 根據 docker-compose.yml 運行 container docker-compose down # 關閉 docker-compose 所 maintain 的 container ``` PS. port 開著外面的人就可以連,所以服務平常沒在用就盡量關掉它