镜像操作
docker images 参数
-a, --all 显示所有详细信息
–digests 显示摘要
-f, --filter filter Filter output based on conditions provided
–format string Pretty-print images using a Go template
–no-trunc Don’t truncate output
-q, --quiet Only show numeric IDs
- 显示所有镜像
docker images
- 删除镜像
docker rm image1 image2
- 获取镜像
docker pull ubuntu:13.10
- 查找镜像
docker seacrh python
- 通过镜像创建一个容器
docker run -it runoob/ubuntu:v2 /bin/bash
-i 表示以“交互模式”运行容器
-t 表示容器启动后会进入其命令行。加入这两个参数后,容器创建就能登录进去。即 分配一个伪终端。
–name 为创建的容器命名
-v 表示目录映射关系(前者是宿主机目录,后者是映射到宿主机上的目录,即 宿主机目录:容器中目录),可以使 用多个-v 做多个目录或文件映射。注意:最好做目录映射,在宿主机上做修改,然后 共享到容器上。
-d 在run后面加上-d参数,则会创建一个守护式容器在后台运行(这样创建容器后不 会自动登录容器,如果只加-i -t 两个参数,创建后就会自动进去容器)。
-p 表示端口映射,前者是宿主机端口,后者是容器内的映射端口。可以使用多个-p 做多个端口映射
-e 为容器设置环境变量
–network=host 表示将主机的网络环境映射到容器中,容器的网络与主机相同
- 保存镜像
docker save -o 保存的文件名,以.tar结尾 镜像名
- 加载镜像
docker load -i ./xxx.tar
- 镜像重命名
docker tag 镜像ID 新名:版本号
容器操作
docker container 参数
command | instruction |
---|---|
attach | Attach local standard input, output, and error streams to a running container |
commit | Create a new image from a container’s changes |
cp | Copy files/folders between a container and the local filesystem |
create | Create a new container |
diff | Inspect changes to files or directories on a container’s filesystem |
exec | Run a command in a running container |
export | Export a container’s filesystem as a tar archive |
inspect | Display detailed information on one or more containers |
kill | Kill one or more running containers |
logs | Fetch the logs of a container |
ls | List containers |
pause | Pause all processes within one or more containers |
port | List port mappings or a specific mapping for the container |
prune | Remove all stopped containers |
rename | Rename a container |
restart | Restart one or more containers |
rm | Remove one or more containers |
run | Run a command in a new container |
start | Start one or more stopped containers |
stats | Display a live stream of container(s) resource usage statistics |
stop | Stop one or more running containers |
top | Display the running processes of a container |
unpause | Unpause all processes within one or more containers |
update | Update configuration of one or more containers |
wait | Block until one or more containers stop, then print their exit codes |
- 显示所有容器
docker container ls --all
- 显示运行中的容器
docker ps
- 删除容器
docker rm 容器id
- 查看标准输出
docker logs [ID或者名字]
- 启动,停止,重启
docker start stop restart
- 打包容器成为一个镜像
docker commit -m=“描述信息” -a=“作者” 容器ID 镜像名
将镜像推送到远端仓库(阿里云)
# 登陆至阿里云
sudo docker login --username=阿里云用户名 registry.cn-beijing.aliyuncs.com
sudo docker tag [ImageId] registry.cn-beijing.aliyuncs.com/trs_wangfei/python3.6.8:[镜像版本号]
$ sudo docker push registry.cn-beijing.aliyuncs.com/trs_wangfei/python3.6.8:[镜像版本号]