Docker镜像创建的三种方式
程序员文章站
2022-03-29 23:41:12
...
一: Docker镜像分层
二 镜像创建
2.1 基于已有的镜像容器进行创建
[root@server1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0c6e70581d9 paigeeworld/centos7 "/bin/bash" 22 hours ago Up 22 hours lucid_napier
6e7caa304845 paigeeworld/centos7 "/bin/bash" 22 hours ago Up 22 hours loving_spence
[root@server1 ~]# docker commit -m "new" -a "docker" a0c6e70581d9 docker:test
sha256:b15cf040c4fb83f1a6bb8bbb2ba735352293bfb78180b0078e99d907a8d0fc8f
[root@server1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker test b15cf040c4fb 12 seconds ago 382MB
nginx web 6cf674b9866c 21 hours ago 355MB
2.2 基于本地模板创建
cat debian-7.0-x86-minimal.tar.gz | docker import - docker:new
2.3 基于Dockerfile创建(附Docker基本操作命令)
root@server1 ~]# cd /opt
[root@server1 opt]# mkdir apache #创建apache目录
[root@server1 opt]# cd apache #进入
[root@server1 apache]# vim Dockerfile #编辑docker容器
FROM centos:7
MAINTAINER alis
RUN yum -y update
RUN yum -y install httpd
EXPOSE 80 #打开端口
ADD index.html /var/www/html/index.html
ADD run.sh /run.sh
RUN chmod 755 /run.sh
CMD ["/run.sh"]
[root@server1 apache]# vim run.sh
#!/bin/bash
rm -rf /run/httpd/*
exec /usr/sbin/apachectl -D FOREGROUND
[root@server1 apache]# echo "this is web test" > index.html
[root@server1 apache]# docker build -t httpd:centos . #生成镜像 这里有个 .
[root@server1 apache]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0c6e70581d9 paigeeworld/centos7 "/bin/bash" 22 hours ago Up 22 hours lucid_napier
6e7caa304845 paigeeworld/centos7 "/bin/bash" 22 hours ago Up 22 hours loving_spence
[root@server1 apache]# iptables -F
[root@server1 apache]# setenforce 0
[root@server1 apache]# docker run -d -p 1216:80 httpd:centos #运行新容器
上一篇: JSP创建错误处理页面
下一篇: 持续集成 Java手册