Dockerfile实战构建自己的基础镜像

以下是docker Hub上下载官方仓库的ubuntu14.04镜像(188M),用它来构建合适自己的ubuntu基础镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#this dockerfile uses the ubuntu image
使用docker Hub官方的ubuntu14.04镜像构建
version 0.1
author: hqd8080
指定所创建镜像的基础镜像
FROM ubuntu:14.04

#维护者信息
MAINTAINER github.com/hqd8080

#指定镜像生成的元数据标签信息
LABEL version="0.1"
LABEL description="ubuntu14.04 base image"

#将复制指定的文件到容器中
#格式:ADD

#例子:ADD *.c /code/
ADD sources.list /etc/apt/

#CMD用来启动容器时默认执行的命令
CMD ["/bin/bash"]
构建

sudo docker build -t="hqd8080/my_ubuntu:14.04_base_images" .

1
2
3
sudo docker build中-t表示容器的名字
hqd8080/my_ubuntu中navas表示仓库名(不允许大写),my_ubuntu表示镜像名
my_ubuntu:14.04_base_images后的14.04_base_images是标签,如果没有指定,默认的是latest
1
2
3
4
#hqd8080$ tree.
├── Dockerfile
├── README.md
└── sources.list(从我当前的系统复制过来)
1
2
Successfully built 1a00f5985fdc
Successfully tagged navas/my_ubuntu:14.04_base_images
查看镜像

sudo docker images -a