最近学习了一下的docker相关的东西,下面介绍一下我个人的学习总结和体会。关于docker的详细介绍和优势,在网上随便都可以找得到,就不做介绍了。这个部分的内容比较简单,有Docker基础的朋友可以忽略。

一、Docker 与GitHub类比

Docker 与Github 类比(纯属个人理解、可能有所偏差)
Docker组件 GitHUb要素
镜像仓库(https://hub.docker.com/ 或私有仓库等) 代码仓库(https://github.com/ 或个人仓库等)
镜像 代码
容器 将不同的代码组件融合到一起的项目

二、docker 安装:(以Ubuntu为例)

  安装的docker有两种方式:(推荐使用第二种)

  方式一:

    使用apt源安装docker.io,可能安装版本比较古老;

sudo apt-get update
sudo apt-get install docker.io

  方式二:

    使用curl安装,可以直接安装最新版

sudo apt-get install curl  // 如果没有安装curl的话
curl -sSL https://get.docker.com | sh

  安装完成之后,需要启动:

sudo service docker start

  每次需要使用sudo权限很麻烦,所以将用户添加到docker组中更方便一点,然后重启docker服务。

sudo usermod -aG docker 用户名
service docker restart // 重启

  检查docker是否安装成功,以及docker版本:

docker version

  会得到如下信息,版本可能会不相同

Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:10:22 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm Server:
Engine:
Version: 18.03.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:08:52 2018
OS/Arch: linux/amd64
Experimental: false

三、docker的简单使用:

  1. 由于国内网络限制,可能直接从hub.docker.com 上获取docker镜像可能会花费很长时间,因此,我选择国内的一些加速器:

  使用 /etc/docker/daemon.json来配置 Daemon,若没有daemon.json需要在对应目录下新建一个,然后daemon.json内容如下:

{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}

  2.从docker仓库中获取一个docker镜像:

    1)hello-world镜像试水

  直接运行,会先拉取镜像,然后创建容器

sudo docker run hello-world

  这时候,docker会查询本地是否有hello-world镜像,如果没有,则会从代码仓库中拉取该镜像。

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:bbdaf0ed64b665f3061aeab15b946697dd00845161935d9238ed28e8cfc2581c
Status: Downloaded newer image for hello-world:latest Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal. To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/ For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

  也可以直接拉取镜像

docker pull hello-world

  2)hello-world的相关信息查询:

  查看docker中当前有哪些镜像:

docker images

  查看有哪些容器:

docker ps -a // -a会将所有容器显示出来,而docker ps 只显示正在运行的
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                           PORTS               NAMES
b9bfbac244d2 hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago brave_booth

  可以看到hello-world容器的名称是brave_booth(该名字可以指定)

  查看hello-world容器的相关日志(这个命令很有用,帮助我解决了一些容器运行不起来的问题):

docker logs brave_booth
root@aasV:~# docker logs brave_booth 

Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal. To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/ For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

  查看某个容器的配置信息:

docker inspect brave_booth
[
{
"Id": "b9bfbac244d2adbe4918554f7cdab0a238e7a913c837e91019a4b2a7fa2d89f8",
"Created": "2018-04-13T05:56:22.678087607Z",
"Path": "/hello",
"Args": [],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-04-13T05:56:23.916771803Z",
"FinishedAt": "2018-04-13T05:56:23.946817217Z"
},
"Image": "sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96",
"ResolvConfPath": "/var/lib/docker/containers/b9bfbac244d2adbe4918554f7cdab0a238e7a913c837e91019a4b2a7fa2d89f8/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/b9bfbac244d2adbe4918554f7cdab0a238e7a913c837e91019a4b2a7fa2d89f8/hostname",
"HostsPath": "/var/lib/docker/containers/b9bfbac244d2adbe4918554f7cdab0a238e7a913c837e91019a4b2a7fa2d89f8/hosts", //该容器在主机的物理地址,很有用哦
"LogPath": "/var/lib/docker/containers/b9bfbac244d2adbe4918554f7cdab0a238e7a913c837e91019a4b2a7fa2d89f8/b9bfbac244d2adbe4918554f7cdab0a238e7a913c837e91019a4b2a7fa2d89f8-json.log",
"Name": "/brave_booth",
"RestartCount": 0,
"Driver": "aufs",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Data": null,
"Name": "aufs"
},
"Mounts": [],
"Config": {
"Hostname": "b9bfbac244d2",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/hello"
],
"ArgsEscaped": true,
"Image": "hello-world",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "700ca800a7f8b43a7d69193f443672eb8d9ae1249fbe4eed3c1d0d9d5e838344",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/700ca800a7f8",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "1086453e378b89bade50ea64c981d42e92cb39aaa7cdf4ac68c70c4411e174dd",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]

四、尝试实践与资源总结:

  docker中文网站:https://www.docker-cn.com/

  菜鸟教程:http://www.runoob.com/docker/ubuntu-docker-install.html

  我尝试在docker容器中在安装一个ubuntu镜像,然后对该镜像进行相关操作。

  执行命令:

sudo docker exec -it containerID或containerName /bin/bash

  成功进入ubuntu容器,然后在该容器中安装了nginx,可参照该网站http://wiki.ubuntu.org.cn/Nginx安装,并成功启动使用。然而启动了nginx之后,发现在容器内部使用curl访问localhost是没有问题的,那么我如何才能在本地机器上访问该容器内部的nginx呢?

  那么肯定是找到docker为该容易分配的IP地址嘛,经过一番尝试,发现之前使用的命令docker inspect 还是最大的突破口

  使用命令:

docker inspect 容器ID | grep IPAddress

  成功找到该容器的IP地址172.17.0.2。在本地主机浏览器中访问172.17.0.2,看到nginx的欢迎页,真的很激动哦。

  

  

  

  

Docker----起步的更多相关文章

  1. Docker----与Asp.net core 的完美结合,在docker容器中创建Asp.Net Core 项目

    在腾讯云上买了一个小容量的服务器,搭建一个docker环境后,可以尝试做一些单系统做起来很麻烦的东西.譬如说,你在windows OS或UbuntuOS中,突然想玩CentOS了,你可以选择将电脑再装 ...

  2. docker init 起步

    #yum install wget http://fedora.mirror.nexicom.net/epel/6/x86_64/epel-release-6-8.noarch.rpm yum -y ...

  3. Docker学习:起步篇

    Docker-概述 学习资源 最好的资源在官网! Docker官方: Docker 官方主页: https://www.docker.com(opens new window) Docker 官方博客 ...

  4. 初识Docker和Windows Server容器

    概览 伴随着Windows Server 2016 Technical Preview 3 (TP3)版本的发布,微软首次提供了Windows平台下地原生容器.它集成了Docker对Windows S ...

  5. 【转】OpenStack和Docker、ServerLess能不能决定云计算胜负吗?

    还记得在十多年前,SaaS鼻祖SalesForce喊出的口号『No Software』吗?SalesForce在这个口号声中开创了SaaS行业,并成为当今市值460亿美元的SaaS之王.今天谈谈『No ...

  6. Hadoop on Docker

    最初接触Docker是在2013年初,当时Docker才刚起步不久,知之甚少.在不到一年的时间里,Docker已经家喻户晓,成为时下最热门的云计算技术之一,出现了许多围绕docker的新兴产品(仅供参 ...

  7. 什么是 docker?

    关于 Docker 是什么,有个著名的隐喻:集装箱.但是它却起了个“码头工人”( docker 的英文翻译)的名字.这无疑给使用者很多暗示:“快来用吧!用了 Docker ,就像世界出现了集装箱,这样 ...

  8. Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦

    个人博客 对于技术人员来说,拥有自己的个人博客应该是一件令人向往的事情,可以记录和分享自己的观点,想到这件事就觉得有意思,但是刚开始写博客的时候脑海中是没有搭建个人博客这一想法的,因为刚起步的时候连我 ...

  9. 学习 Kubernetes 的 Why 和 How - 每天5分钟玩转 Docker 容器技术(114)

    这是一个系统学习 Kubernetes 的教程,有下面两个特点: 系统讲解当前最流行的容器编排引擎 Kubernetes包括了安装部署.应用管理.网络.存储.监控.日志管理等多各个方面. 重实践并兼顾 ...

  10. 从一到万的运维之路,说一说VM/Docker/Kubernetes/ServiceMesh

    摘要:本文从单机真机运营的历史讲起,逐步介绍虚拟化.容器化.Docker.Kubernetes.ServiceMesh的发展历程.并重点介绍了容器化阶段之后,各项重点技术的安装.使用.运维知识.可以说 ...

随机推荐

  1. 1. 初识 Lucene

    在学习Lucene之前呢,我们当然首先要了解下什么是Lucene. 0x01 什么是Lucene ? Lucene是一套用于全文检索和搜索的开放源代码程序库,由Apache软件基金会支持和提供. Lu ...

  2. WPF笔记1 用VS2015创建WPF程序

    使用WPF创建第一个应用程序.实现功能如下: 单击"Red"按钮,文本显示红色:单击"Black"按钮,文本显示黑色:单击"Back"按钮, ...

  3. 一、Python安装与Pycharm使用入门

    一.安装Python 1.Linux下安装 一般系统默认已安装2.6.6版本,升级成2.7版本, 但 2.6 不能删除,因为系统对它有依赖,epel源里最新的也是2.6版本,所以以源代码的方式安装2. ...

  4. 小程序之Tab切换

    小程序越来越火了,作为一名,额  有理想的攻城狮,当然要紧跟互联网时代的步伐啦,于是我赶紧抽时间学习了一下小程序的开发,顺便把经验分享给大家. 对于申请账号以及安装开发工具等,大家可以看官网:http ...

  5. centos安装包选择--liveCD、liveDVD、bin-DVD、netinstall和minimal

    在Centos官方选择下载centos的时候有好几个文件可供下载,包括liveCD.liveDVD和bin-DVD等等.这些文件都有什么区别,我们应该选择哪个文件下载呢? liveDVD版本:它就是一 ...

  6. .Net的垃圾回收机制(GC)之拙见——托管类型的垃圾回收

    各种语言的垃圾回收在IT界噪的沸沸扬扬,有极大的优化同时也有瓶颈. 而在.Net中的垃圾回收机制又是怎样的呢? 众所知周,.Net中的垃圾回收机制是由.Net Framework托管的,带给开发者最大 ...

  7. Kaggle竞赛 —— 房价预测 (House Prices)

    完整代码见kaggle kernel 或 Github 比赛页面:https://www.kaggle.com/c/house-prices-advanced-regression-technique ...

  8. JDK1.8源码(六)——java.util.LinkedList 类

    上一篇博客我们介绍了List集合的一种典型实现 ArrayList,我们知道 ArrayList 是由数组构成的,本篇博客我们介绍 List 集合的另一种典型实现 LinkedList,这是一个有链表 ...

  9. Beta项目复审

    Beta项目复审 复审人:张宇光 所属团队:MyGod 团队成员:程环宇.王田路.张芷祎.张宇光.王婷婷 团队排名: SW_HW4-team团队 hyw-team团队 Java-Team团队 C++团 ...

  10. 敏捷开发冲刺--day3

    1 团队介绍 团队组成: PM:齐爽爽(258) 小组成员:马帅(248),何健(267),蔡凯峰(285)  Git链接:https://github.com/WHUSE2017/C-team 2 ...