覆盖在学习和工作中的常用 Docker 命令 :Image / Container / Storage / Network
目录 Table of Contents
Image 查看 1 2 3 4 5 6 7 8 docker images docker images -a docker images -aq docker inspect ${registry} :${tag} docker inspect ${image_id}
制作 1 docker build --network ${network_mode} -f /path/to/dockerfile -t ${registry} :${tag} /path/to/data
保存 1 2 3 docker save -o ${output} .tar ${registry} :${tag} docker save -o ${output} .tar ${image_id}
加载 1 2 docker load -i ${input} .tar
修改 1 docker tag ${image_id} ${registry} :${tag}
删除 1 2 3 4 5 docker rmi -f $(docker images -aq) docker rmi -f ${registry} :${tag} docker rmi -f ${image_id}
Dockerfile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 FROM ubuntu MAINTAINER lottewong <lottewong21@gmail.com> RUN apt-get update && \ apt-get install -y python3 \ python3-dev \ python3-pip \ openssl \ libssl-dev \ libffi-dev \ net-tools \ sqlite3 && \ ln -s /usr/bin/python3 /usr/bin/python && \ ln -s /usr/bin/pip3 /usr/bin/pip && \ apt install -y vim lsof curl RUN mkdir -p /data/test -proj/dependencies && \ mkdir -p /var/log /test -proj WORKDIR /data/test -proj COPY dependencies dependencies RUN cd dependencies && \ pip install -r requirements.txt && \ tar -zvxf some-package.tar.gz && \ rm -rf some-package.tar.gz && \ cd /data/test -proj/dependencies/some-package && python setup.py install
Container 查看 1 2 3 4 5 docker ps docker ps -a docker ps -aq
运行 1 2 3 4 5 6 7 8 9 docker run --name=${container_name} -d -p ${host_port} :${ctnr_port} -v /path/to/host:/path/to/ctnr ${registry} :${tag} (${command} ) docker run --name=${container_name} -it -p ${host_port} :${ctnr_port} -v /path/to/host:/path/to/ctnr ${image_id} (${command} )
执行 1 2 3 docker exec -it ${container_name} ${command} docker exec -it ${container_id} ${command}
启动 1 2 docker start ${container_name} docker start ${container_id}
暂停 1 2 docker stop ${container_name} docker stop ${container_id}
重启 1 2 docker restart ${container_name} docker restart ${container_id}
删除 1 2 3 4 5 docker rm -f $(docker ps -aq) docker rm -f ${container_name} docker rm -f ${container_id}
提交 1 2 docker commit -a "${author} " -m "${message} " ${container_name} ${registry} :${tag} docker commit -a "${author} " -m "${message} " ${container_id} ${registry} :${tag}
导出 1 2 3 docker export ${container_name} > ${export} .tar docker export ${container_id} > ${export} .tar
导入 1 2 cat ${import} .tar | docker import - ${registry} :${tag}
传输 1 2 3 4 docker cp ${container} :/path/to/ctnr /path/to/host docker cp /path/to/host ${container} :/path/to/ctnr
日志 1 2 docker logs ${container_name} docker logs ${container_id}
监控 1 2 docker stats --no-stream ${container_name} docker stats --no-stream ${container_id}
Storage
Network