5.docker image (镜像)
1.image 是什么
是文件和 meta data 的集合 (root filesystem)
是分層的,并且每一層都可以添加改變刪除文件,成為一個新的image
不同的image可以共享相同的layer #4 和 #2 可以共享 centos image
image 本身是只讀的
2.image的獲取
從文件( dockerFile )獲取
dockerFile內(nèi)容如下
FROM ubantu_16_04 #基礎 image 為 ubantu_16_04? 類似于操作系統(tǒng)為 ubantu 16 04
LABEL maintainer="eaon <eaon@163.com>" ? ?#基本標識? 例如作者和郵箱
RUN apt-get update && apt-get install -y redis-server ? #在 基礎image 上運行一段 安裝程序的命令
EXPOSE 6379 #要暴露的端口號
ENTRYPOINT? [ "/usr/bin/redis-server" ] ? # 程序的入口
從 dockerFile 運行
docker build -t eaon03/redis:latest? .? ?#表示從當前的 dockerFile 建立名為?eaon03/redis:latest 的鏡像
從 registry 拉取 ( 從遠程倉庫拉取 registry 類似與 github )?
如果 docker 太慢或者超時 可以切換docker源
sudo docker pull hello-world
(具體的鏡像 可以從 hub.docker.com 上進行加下載)
sudo docker image ls? 查看本地的image列表
3.制作base image (例如 hello-world)
創(chuàng)建一個hello-world 目錄 并 進入
mkdir hello-world
cd hello-world
寫一個 .c 文件?
vim? hello.c
#include<stdio.h>
int main()
{printf("hello docker!\n");}
安裝 gcc glibc-static
sudo yum install -y gcc glibc-static
編譯 c 文件為二進制文件
gcc -static hello.c -o hello
編寫Dockerfile
vim Dockerfile
FROM scratch
ADD hello /
CMD ["/hello"]
添加鏡像
docker build -t eaon/hello-world .
運行鏡像
docker run eaon/hello-world
4.centos 虛擬機去除 sudo
1.?添加docker 用戶組
sudo groupadd docker
2.將vagrant 用戶 添加到 docker 用戶組內(nèi)
? ?sudo gpasswd -a vagrant docker
3.重啟docker 進程
sudo service docker restart
4.重新登陸
轉載于:https://www.cnblogs.com/zonehoo/p/11235303.html
總結
以上是生活随笔為你收集整理的5.docker image (镜像)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 诺基亚7.2 刷TWRP
- 下一篇: DAMA数据管理知识体系简介