Docker 基本用法(镜像的下载和使用)
拉取镜像
docker pull centos:centos7
查看镜像
docker images
运行容器
docker run -itd --name centos-test centos:centos7
查看进程
docker ps
启动容器
docker start {ID|NAME}
进入容器操作
docker exec -it {ID|NAME} /bin/bash
复制文件
docker cp {ID|NAME}:/XXX ./XXX
删除容器和镜像
docker stop {ID|NAME} # 停止容器
docker rm {ID|NAME} # 删除容器
docker rmi {ID|NAME} # 删除镜像
镜像导出
涉及的命令有
export
、import
、save
、load
export
镜像导入导出一般用在迁移上,如容器迁移等。需要用到容器id
docker export 1a47a2ca6a63 > ub.tar
导入也同理
docker import - new_hangger_server < ub.tar
提交
root@hcss-ecs-c875:~/foo# docker commit --help
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
Aliases:
docker container commit, docker commit
Options:
-a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Commit message
-p, --pause Pause container during commit (default true)
root@hcss-ecs-c875:~/foo#
例子如下:第一个参数是容器ID,第二个是起的别名和版本号
docker commit e96ea9be4cfc ubuntu1:2.0
save导出
root@hcss-ecs-c875:~/foo# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Aliases:
docker image save, docker save
Options:
-o, --output string Write to a file, instead of STDOUT
root@hcss-ecs-c875:~/foo#
例子如下:第一个参数为输出文件,第二个是提交的镜像和版本号
docker save -o ubuntu2.tar ubuntu1:2.0
标题:Docker 基本用法(镜像的下载和使用)
作者:llilei
地址:http://solo.llilei.work/articles/2021/03/12/1615531741826.html