Docker: 建立儲存映象
阿新 • • 發佈:2020-12-11
映象的建立和儲存
- 基於現有父映象開發並commit
- 使用Dockerfile檔案建立
一.基於現有父映象開發並commit
- pull and start a new container
docker pull ubuntu:18.04
docker run -it ubuntu:18.04 bash
-
deploy app and edit /run.sh
-
exit and commit this container
// docker commit ID SW_NAME:VERSION // example: root@13336c183077:/# exit exit bear@k40 ~% docker commit 13336c183077 ubuntu.18.04:v1
- run the new container by run.sh
docker run ubuntu.18.04:v1 /run.sh
二.使用Dockerfile檔案建立
- touch a new Dockerfile and edit:
FROM nginx
RUN echo 'I'm nginx' > /usr/share/nginx/html/index.html
- FROM: IMAGE, base 父映象
- RUN:["可執行檔案", "引數1", "引數2"], like RUN ["./test.php", "dev", "offline"] == RUN ./test.php dev offline
注意:
FROM centos RUN yum install wget RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" RUN tar -xvf redis.tar.gz 以上執行會建立 3 層映象。可簡化為以下格式: FROM centos RUN yum install wget \ && wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" \ && tar -xvf redis.tar.gz
- build new image
當前目錄.
上下文路徑建立映象:
docker build -t myimage:v1 .