dockerfile镜像制作
1.创建镜像目录
mkdir imgl
2.创建Dockerfile
cd imgl
vim Dockerfile
进入编辑模式
# Descriprion: test image
FROM busybox:latest
MAINTAINER "myt2000 <myt2000@126.com>"
# LABEL maintainer= "myt2000 <myt2000@126.com>"
COPY index.html /data/web/html/
COPY yum.repos.d /etc/yum.repos.d/
创建index.html 并写入内容
将/etc/yum.repos.d 拷贝如imgl目录下
3.创建镜像
[root@localhost imgl]# docker build -t tinyhttpd:v0.1-1 ./
Sending build context to Docker daemon 22.53kB
Step 1/4 : FROM busybox:latest
---> e4db68de4ff2
Step 2/4 : MAINTAINER "myt2000 <myt2000@126.com>"
---> Using cache
---> 16c2f515051b
Step 3/4 : COPY index.html /data/web/html/
---> Using cache
---> 80277675b1c3
Step 4/4 : COPY yum.repos.d /etc/yum.repos.d/
---> c58ae4523e4b
Successfully built c58ae4523e4b
Successfully tagged tinyhttpd:v0.1-1
查看镜像
[root@localhost imgl]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
tinyhttpd v0.1-1 c58ae4523e4b About a minute ago 1.24MB
4.启动镜像
[root@localhost imgl]# docker run --name tinyweb1 --rm tinyhttpd:v0.1-1 cat /data/web/html/index.html
<h1>busybox .hi</h1>
[root@localhost imgl]# docker run --name tinyweb1 --rm tinyhttpd:v0.1-1 ls /etc/yum.repos.d/
CentOS-Base.repo
CentOS-CR.repo
CentOS-Debuginfo.repo
CentOS-Media.repo
CentOS-Sources.repo
CentOS-Vault.repo
CentOS-fasttrack.repo
docker-ce.repo
5.ADD命令
Dockerfile
# Descriprion: test image
FROM busybox:latest
MAINTAINER "myt2000 <myt2000@126.com>"
# LABEL maintainer= "myt2000 <myt2000@126.com>"
COPY index.html /data/web/html/
COPY yum.repos.d /etc/yum.repos.d/
ADD http://nginx.org/download/nginx-1.17.1.tar.gz /usr/local/src/
[root@localhost imgl]# docker build -t tinyhttpd:v0.1-3 ./
Sending build context to Docker daemon 22.53kB
Step 1/5 : FROM busybox:latest
---> e4db68de4ff2
Step 2/5 : MAINTAINER "myt2000 <myt2000@126.com>"
---> Using cache
---> 16c2f515051b
Step 3/5 : COPY index.html /data/web/html/
---> Using cache
---> 80277675b1c3
Step 4/5 : COPY yum.repos.d /etc/yum.repos.d/
---> Using cache
---> c58ae4523e4b
Step 5/5 : ADD http://nginx.org/download/nginx-1.17.1.tar.gz /usr/local/src/
Downloading 1.033MB/1.033MB
---> 1c1cc18ce353
Successfully built 1c1cc18ce353
Successfully tagged tinyhttpd:v0.1-3