制作Docker镜像与运行容器

febootstrap制作docker镜像工具的变名
yum -y install supermin
 

作CentOS镜像文件centos6-image目录:

supermin -i bash -i wget -i yum -i iputils -i iproute -i man -i vim -i openssh-server -i openssh-clients -i tar -i gzip centos7 centos7-image http://mirrors.aliyun.com/centos/7/os/x86_64/


 创建镜像:(以下命令需要使用root运行)
#  supermin5 -v --prepare bash coreutils gcc rpm librpm make yum openssh-server -o supermin.d
# supermin5 -v --build --format chroot supermin.d -o appliance.d
# echo 7 > appliance.d/etc/yum/vars/releasever
# tar --numeric-owner -cpf centos-7.tar -C appliance.d .
# cat centos-7.tar | docker import -zhangjian/centos-7
 
查看镜像:
docker images

运行:
docker run -i -t zhangjian/centos-7 /bin/bash

使用 docker cp 命令
docker cp <containerId>:/file/path/within/container /host/path/target

网络:
docker run -i -t --net="host" kongxx/centos-7 /bin/bash

镜像改名:
docker tag d7852422d6c5 docker.io/promanz:redhat



docker images往往不知不觉就占满了硬盘空间,为了清理冗余的image,可采用以下方法:

1.进入root权限

sudo su

2.停止所有的container,这样才能够删除其中的images:

docker stop $(docker ps -a -q)

3.查看当前有些什么images

docker images

4.删除images,通过image的id来指定删除谁

docker rmi <image id>

5.如果无法删除,可能是有容器依赖这个镜像,先删容器,列出所有容器
docker ps -a

6.删除容器
docker rm <CONTAINER ID>

7.删除镜像
docker rmi <image id>

完成

Docker导出:

docker export <containerId> > centos.tar

删除所有容器:

docker rm `docker ps -a |awk '{print $1}' | grep [0-9a-z]`

以host网络模式运行容器并指定启动一个命令行

docker run -i --net="host" zaki/centos7base /bin/bash -c "/usr/sbin/sshd -d"

启动一个sshd,并使用主机网络后台运行

docker run -d --net="host" uft/database /usr/sbin/sshd -d

指定docker镜像根目录:

dockerd --graph=/home/docker &

docker exec -it adgfaegae bash

猜你喜欢

转载自blog.csdn.net/promanz/article/details/89404154