python_note
  • Introduction
  • My Python
    • Anaconda
    • argparse
    • datetime
    • json
    • logging
    • numpy
    • open
    • openCC
    • pandas & csv
    • Socket & SocketServer
    • re
    • yaml
    • smtp
    • 物件操作
    • unittest
    • 線程
    • prettytable
    • IO
    • pycurl
    • sys
    • pickle
    • auto-python-to-exe
    • cython
    • nuitka
  • Crawler
    • Urllib & Requests
      • User-agent
      • Percent-Encoding
      • mail code
    • Selenium
    • TCP & UDP
    • 控制字符(control character)
  • Web Development
    • Flask
      • RESTful api
      • Template
      • blueprint
    • Django
      • 環境佈署(windows)
    • 檢查Port
    • Apache
    • 使用者行為
    • jQuery
    • 壓力測試
    • DataTable
    • Bootstrap
    • CSS
    • JavaScript
    • Chart.js
  • Deep Learning
    • Keras 設定
    • RNN
    • LSTM
  • Test
    • T-Test
  • 資料結構
    • Hash
    • 時間複雜度
  • NLP
    • N-gram
    • CKIP
    • 中文轉數字
    • CRF
    • Mutual Information
    • 模糊比對
  • Linebot
    • Heroku
    • 圖文選單
    • channel
  • Linux
    • 常用指令
    • shell script
    • sshfs
    • ssh
    • nodejs & npm
    • debug
  • GCP
    • app engine
    • ssh(gcp)
    • gsutil
    • brabrabra
    • Load Balancer
    • k8s
  • Database
    • mysql
    • elasticsearch
      • Query
      • Backup and Restore
      • elasticdump
      • es2csv
      • ELK
    • mongodb
      • install
      • authentication
      • pymongo
    • sql server
  • go
    • Swarm
  • Docker
    • Kitematic
    • Dockerfile
    • Swarm
  • Git
  • 其他
    • USB軟體保護
    • Windows效能監視器
  • Blockchain
Powered by GitBook
On this page
  • 什麼是Dockerfile ?
  • 組成
  • 註解可用#

Was this helpful?

  1. Docker

Dockerfile

什麼是Dockerfile ?

  • 是一個文字檔,由一行一行的指令所組成,用來描述這個映像檔應該長成怎麼樣

  • 利用Dockerfile可以建構/客製化出自己獨一無二的映像檔

  • 由於Dockerfile中可以清楚的知道映像檔的組成,因此,在安全性上會有所提升

  • 因為是純文字檔,所以檔案很小、很容易分享

組成

由一行一行的指令列所組成,一行指令對Image來說就是一層的資料層(Layer),

一個Image就是靠這樣一層一層的資料累加上去,最後才編譯出自己想要的映像檔

註解可用#

FROM

基底映像檔,必需是「第一個」指令行,指定最基本的image

FROM ubuntu:15.04 或
FROM ubuntu

MAINTAINER

映像檔維護者,把它想成是作者即可

MAINTAINER pan 或
MAINTAINER pan@gmail.com

LABEL

設定映像檔的Metadata資訊,中間用空白鍵隔開

LABEL <key>=<value> <key>=<value> <key>=<value> ...

比MAINTAINER方便一些

如果要查詢LABEL的資訊:

docker inspect []

RUN

每加一個RUN,就會在基底映像層加上一層資料層,可以利用RUN來安裝套件

  • RUN <command>

以shell的形式執行,Linux的預設是/bin/sh -c,而Windows上的預設環境則是cmd /S /C

  • RUN ["executable", "param1", "param2"]

以exec的形式執行指令,例如Linux上不想用預設的shell執行指令

那麼就可以透過RUN ["/bin/bash", "-c", "echo hello"]指定想要的shell

若希望有Shell處理的功能,記得要自行加入

在使用RUN指令時,有以下注意要點:

  • 如果想要執行的指令很長,可以利用\符號來換行,比較容易閱讀

  • 使用exec形式執行時,必需使用JSON array的格式,因此,請使用雙引號

  • 每一個RUN就會新增一層資料層,為了減少不必要的資料層,可以利用&&來串連多個命令

範例

# install packages, only for demo
RUN mkdir -p /home/demo/docker
RUN ["apt-get", "install", "python3"]
RUN apt-get update && apt-get install -y --force-yes apache2 \
    firefox \
    php5

CMD

PreviousKitematicNextSwarm

Last updated 5 years ago

Was this helpful?