Docker on Windows初体验
写在前面:之前想在WIN 10 系统装TensoFlow,所以follow到了Docker这个黑科技,花了一天时间安装熟悉了一下。如果需要在多台机器需要部署环境用docker就可以事半功倍了,所以可以看到当前很多开源框架都有docker版本,安装配置一步到位。不过Docker还是linux环境,在windows下运行其实是在虚拟机上运行。本文是我用安装使用Docker的笔记,基本是按着官网教程,很好上手,先get这个装备,以后肯定能用上。
https://docs.docker.com/docker-for-windows/
先简单百度百科了解一下:
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
1.下载window版本安装包
2.安装,重启
64bit Windows 10 Pro, Enterprise and Education (1511 November update, Build 10586 or later). In the future we will support more versions of Windows 10.
The Hyper-V package must be enabled. The Docker for Windows installer will enable it for you, if needed. (This requires a reboot).
3.测试
运行Docker for Windows,安装完会有快捷方式
扫描二维码关注公众号,回复: 3811111 查看本文章打开 cmd 运行
docker run hello-world
查看当前系统中所有容器
Run
docker ps -a
to show all containers on the system.
4.注册Docker Hub账号:可以下载上传镜像
5.runs the whalesay image in a container
如果是第一次在本地容器运行这个镜像,docker会在本地查找,如果没有这个镜像,就会去hub上下载并运行(有点像git)The first time you run a software image, the docker command looks for it on your local system. If the image isn’t there, then docker gets it from the hub.
6.关于镜像和容器
到这里基本上能理解images和container了,通俗来讲,images是已经打包好的环境文件,我们运行的时候把images加载运行在本地容器中,你在这个容器里进行一些修改后可以重新打包成新的镜像并上传。
docker images
The command lists all the images on your local system. You should see docker/whalesay in the list.
7.修改默认路径
如果一直默认在C盘的话,随着你不断加载镜像下载镜像,C盘会被占很大空间,可以通过移动来改变虚拟机默认硬盘位置
打开虚拟机管理器,移动,根据提示下一步下一步就行
还不清楚可以参考下这个博客:
8.根据已有镜像修改并保存
①查找镜像
docker search sinatra
②下到本地
docker pull training/sinatra
③打开运行
docker run -t -i training/sinatra /bin/bash
④创建自己的镜像
You can update a container created from an image and commit the results to an image.
You can use a Dockerfile to specify instructions to create an image.
可以直接在刚才pull下来的镜像做一些修改后
docker commit -m "Added test" -a "zhenghaungcheng" \ a53427854867 ouruser/sinatra:v2
-m是一些提交的信息 -a 是作者名字,注意这里的”a53427854867”是你需要提交的容器的ID(可以执行
docker ps
查看),最后就是你要保存新的镜像的名字。You’ve specified two flags: -m and -a. The -m flag allows us to specify a commit message, much like you would with a commit on a version control system. The -a flag allows us to specify an author for our update.
Building an image from a Dockerfile 暂时不研究了
9.容器镜相关命令
查看当前运行容器
docker ps
docker ps -l
16de97c812b4 ubuntu:16.04 “/bin/bash”
3 hours ago Exited (0) 2 hours ago sharp_poitras
关闭容器
docker stop
Note: Always remember that removing a container is final!
可以把当前的一些容器保存成新的镜像:
docker commit -m “Added test” -a “zhenghaungcheng” a53427854867 ouruser/sinatra:v2
docker commit -m “Added test” -a “zhenghaungcheng” 16de97c812b4 ubuntu/python
docker run -t -i ubuntu/python /bin/bash
10.其它一些常用命令
docker images –digests 查看镜像摘要信息(标识)
Images that use the v2 or later format have a content-addressable identifier called a digest. As long as the input used to generate the image is unchanged, the digest value is predictable. To list image digest values, use the –digests flag:
When pushing or pulling to a 2.0 registry, the push or pull command output includes the image digest. You can pull using a digest value.
docker pull ouruser/sinatra@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf
Push an image to Docker Hub
docker push ubuntu/python
Remove an image from the host
docker rmi training/sinatra
Remove container
docker rm -v 158829b3340e