Home Docker Cheat Sheet
Post
Cancel

Docker Cheat Sheet

Update Date: 2024-01-02

1. Docker

Build Images

1
docker build

suffixes

--no-cached: 避免在build 時被cache 住,而使修改的部分無法build

Check Images

1
docker images

Run Images

1
docker run {ImageName}

suffixes

2. Dockerfile

Format

The dockerfile helps us run the image automatically by just docker run.

The example is as follow 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
FROM centos:7
MAINTAINER jack

RUN yum install -y wget

RUN cd /

ADD jdk-8u152-linux-x64.tar.gz /

RUN wget http://apache.stu.edu.tw/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz
RUN tar zxvf apache-tomcat-7.0.82.tar.gz

ENV JAVA_HOME=/jdk1.8.0_152
ENV PATH=$PATH:/jdk1.8.0_152/bin
CMD ["/apache-tomcat-7.0.82/bin/catalina.sh", "run"]

FROM: 會使用到的docker image 名稱
MAINTAINER: 單純紀錄是誰寫的,也可用email
RUN: 指令後面加linux command,可用來安裝或設定image 所需的東西 ADD: 把local 的東西複製到image 裡。若是tar.gz 被複製進去時,會自動解壓縮。類似的有像是COPY,但ADD更進階一些2 ENV: 設定環境變數 CMD: 在執行docker run 後啟動image 以後台的方式執行。

Reference

  1. https://ithelp.ithome.com.tw/articles/10191016?sc=hot 

  2. https://yeasy.gitbook.io/docker_practice/image/dockerfile/add 

This post is licensed under CC BY 4.0 by the author.