⭐基于已有的镜像容器进行创建⭐
1、查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd centos f33378996fc9 3 hours ago 401MB
nginx latest 231d40e811cd 4 weeks ago 126MB
centos latest 0f3e07c0138f 2 months ago 220MB
registry latest f32a97de94e1 9 months ago 25.8MB
2、查看容器
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
98f4a5e9f3cb httpd:centos "/run.sh" 3 hours ago Up 3 hours 0.0.0.0:1216->80/tcp trusting_knuth
4e7a7c83f17c b71efbdcd81c "/bin/sh -c 'yun ins…" 3 hours ago Exited (127) 3 hours ago goofy_liskov
55ce6b7cc01c b71efbdcd81c "/bin/sh -c 'yun ins…" 3 hours ago Exited (127) 3 hours ago bold_nobel
0f6797198de1 centos "/bin/bash" 5 hours ago Exited (0) 4 hours ago great_aryabhata
4569844804c4 centos "/bin/bash" 5 hours ago Exited (0) 5 hours ago web100
55cb15445eae centos "/bin/bash" 5 hours ago Exited (0) 5 hours ago web1
3、批量删除容器
[root@localhost ~]# docker ps -a | awk '{print "docker rm "$1}' | bash
Error: No such container: CONTAINER
4e7a7c83f17c
55ce6b7cc01c
0f6797198de1
4569844804c4
55cb15445eae
4、在进行容器的查看
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5、创建容器并查看
[root@localhost ~]# docker create -it centos /bin/bash
4cb84df361e4164f8e1c74648a58881b6a9f95cb0b28dc3671a56ec2088b418d
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4cb84df361e4 centos "/bin/bash" 4 seconds ago Created compassionate_jones
[root@localhost ~]# docker commit -m "new" -a "daoke" 4cb84df361e4 daoke:centos
sha256:c60576c63194d09d227ed7820cac2c753fc9436b952987cb78503d99ec719e09
[root@localhost ~]# docker images | grep daoke
daoke centos c60576c63194 About a minute ago 220MB
⭐基于本地模板创建⭐
1、远程共享
[root@localhost abc]# mount.cifs //192.168.100.7/rpm /mnt/
Password for root@//192.168.100.7/rpm:
2、基于模板去进行创建
(1)未创建前进行查看
[root@localhost mnt]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
(2)创建镜像
[root@localhost mnt]# cat debian-7.0-x86-minimal.tar.gz | docker import - daoke:centos
sha256:c2a082e2d87027181d6a3ec31e36144a088f7f38244dfa9a3634093ea34ec707
(3)创建好后进行查看
[root@localhost mnt]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
daoke centos c2a082e2d870 21 seconds ago 215MB
⭐ Dockerfile文件⭐
1、创建目录
mkdir apache
cd apache
2、写配置
(1)vim Dockerfile
#基于的基础镜像
FROM centos
#维护镜像的用户信息
MAINTAINER The porject <cloud-ops@centos.org>
#镜像操作指令安装apache软件
RUN yum -y update
RUN yum install -y httpd
#开启80端口
EXPOSE 80
#复制网站首页文件
ADD index.html /var/www/html/index.html
#将执行脚本复制到镜像中
ADD run.sh /run.sh
RUN chmod 755 /run.sh
#启动容器时执行脚本
CMD ["/run.sh"]
(2)vim run.sh
#!/bin/bash
rm -rf /run/httpd/*
exec /usr/sbin/apachectl -D FOREGROUND
(3)echo "web test" > index.html
3、生成镜像
docker build -t httpd:centos .
4、新镜像运行容器
docker run -d -p 1216:80 httpd:centos
5、测试
http://192.168.35.200:1216/