【Docker】docker 学习

来源:互联网 发布:如何评价詹姆斯知乎 编辑:程序博客网 时间:2024/06/05 03:06

docker 学习:

docker  包含,镜像,仓库,容器,使用的时候,需要将镜像从仓库中拉到本地,用命令将镜像运行起来,变成容器。


1.windows 10之外系统 安装 docker。

(win10下载链接:点击下载)

(其他 Windows:点击下载)



下载完成之后,双击安装,一路默认,知道安装完成,桌面上出现很多图标

如下图:



双击图中的 Docker QuickstartTerminal  启动 docker终端  等待,它会自动下载一些东西。下载完成之后,输入命令 docker -v 查询docker 版本   显示出版本信息,表示docker安装成功。


2,使用docker 

接下来我们要开始使用docker 


首先我们会使用到两个命令 

docker pull   从仓库中拉取

docker images  查看本地有哪些镜像



下载镜像    docker pull hello-world     

这里可能有疑问,我直接写了这个命令,没有写地址,这个hello-world 是从哪里下载下来的。当我们没有指定下载的路径的时候,他是默认到docker 官方的仓库下载的镜像。


运行此条命令过程是:

首先会在本地检查拉取的镜像是否存在,不存在就去仓库中去拉取到本地。


运行一个镜像   docker run image 

运行词条命令的过程是:

也是首先在本地检查运行的镜像是否存在,不存在就去仓库中拉取到本地来。相当于执行了一个docker pull 操作。




运行镜像时指定端口,也就是映射端口,在windows下面我们要执行  docker-machine ip default

原因:

引用

The reason you’re having this, is because on Linux, the docker daemon (and your containers) run on the Linux machine itself, so “localhost” is also the host that the container is running on, and the ports are mapped to.

On Windows (and OS X), the docker daemon, and your containers cannot run natively, so only the docker client is running on your Windows machine, but the daemon (and your containers) run in a VirtualBox Virtual Machine, that runs Linux.

原来,docker是运行在Linux上的,在Windows中运行docker,实际上还是在Windows下先安装了一个Linux环境,然后在这个系统中运行的docker。也就是说,服务中使用的localhost指的是这个Linux环境的地址,而不是我们的宿主环境Windows。我们可以通过命令

最后通过如图链接访问成功




一下我记录下学习docker 我用到的一些命令:

1,docker pull   [镜像名]      去仓库下载镜像到本地。

2,docker images      查询本地仓库所有镜像。

3,docker run   -d -p 8888:8080   [镜像名]     运行一个镜像 ,加入了一些参数,-d 表示后台运行,-p表示映射端口(docker 与主机映射)。

4,docker exec -it bash   进入容器 终端。

5,docker stop 容器ID  停止容器。

6,docker ps   查看启动的容器。

7,vi Dockerfile   创建一个自己的容器   保存 esc + :wq  保存退出。

举个栗子:

from 这里写某个容器

MAINTAINER  hxj 871378581@qq.com


8,docker build ./    创建容器,  ./(点斜杠)是Dockerfile目录。

9,which 查找文件  在容器里面使用,先执行docker exec -it 容器id bash 

10,docker ps --help    加入  --help  显示命令的帮助

11,windows 查看网络 perfmon -res(当天用到了

12,pwd 查看当前目录



原创粉丝点击