1 安装docker的apt源

apt-get install apt-transport-https ca-certificates curl software-properties-common

2
添加docker官方的GPG

root@zhf-linux:/home#
curl -s https://download.docker.com/linux/ubuntu/gpg | sudo apt-key
add -

OK

3
添加docker的源。如果没有docker.list则自己创建一个

root@zhf-linux:/etc/apt/sources.list.d#
bash -c "echo deb https://get.docker.io/ubuntu docker main >
/etc/apt/sources.list.d/docker.list"

4
安装docker

apt
install docker.io

5
查看docker的版本:

root@zhf-linux:/var/lib/docker#
docker version

Client:

Version:
1.13.1

API
version: 1.26

Go
version: go1.6.2

Git
commit: 092cba3

Built:
Thu Sep 7 17:23:05 2017

OS/Arch:
linux/386

Server:

Version:
1.13.1

API
version: 1.26 (minimum version 1.12)

Go
version: go1.6.2

Git
commit: 092cba3

Built:
Thu Sep 7 17:23:05 2017

OS/Arch:
linux/386

Experimental:
false

到这里docker整个就安装完了,我们来看下如何来启动一个镜像

1
通过docker
run命令来启动一个httpd的镜像。如果没有发现httpd镜像会从docker
hub下载镜像。下载完成后,镜像httpd被保存到本地

docker
run -d -p 80:80 httpd

2
docker images可以看到已经下载到本地

root@zhf-linux:/home/zhf/zhf/c_prj/make_function#
docker images

REPOSITORY
TAG IMAGE ID CREATED
SIZE

httpd
latest 7659d5a9a057 2 weeks ago
189 MB

3
docker ps显示容器正在运行

root@zhf-linux:/home/zhf/zhf/c_prj/make_function#
docker ps

CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES

39ae70ca12b2
httpd "httpd-foreground" 6 minutes
ago Up 6 minutes 0.0.0.0:80->80/tcp
compassionate_bohr

接下来看下如何下载一个镜像。通过docker
pull下载。docker
pull会从Docker
Hub进行下载。

root@zhf-linux:/home/zhf/zhf/c_prj/make_function#
docker pull hello-world

Using
default tag: latest

latest:
Pulling from library/hello-world

cf7dde121f94:
Pull complete

Digest:
sha256:0e06ef5e1945a718b02a8c319e15bae44f47039005530bc617a5d071190ed3fc

Status:
Downloaded newer image for hello-world:latest

通过docker
images看到这个镜像只有600多K

root@zhf-linux:/home/zhf/zhf/c_prj/make_function#
docker images hello-world

REPOSITORY
TAG IMAGE ID CREATED
SIZE

hello-world
latest abd130ec0722 3 months ago
665 kB

通过docker
run hello-world来执行。结果如下:

root@zhf-linux:/home/zhf/zhf/c_prj/make_function#
docker run hello-world

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.

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://cloud.docker.com/

For
more examples and ideas, visit:

https://docs.docker.com/engine/userguide/

下载的docker镜像默认存储路径是/var/lib/docker
.具体的镜像文件就在containers文件夹中

root@zhf-linux:/var/lib/docker#
ls -al

total
44

drwx--x--x
11 root root 4096 Oct 30 22:28 .

drwxr-xr-x
79 root root 4096 Dec 11 21:08 ..

drwx------
5 root root 4096 Oct 30 22:28 aufs

drwx------
8 root root 4096 Dec 19 20:59 containers

drwx------
3 root root 4096 Oct 30 22:28 image

drwxr-x---
3 root root 4096 Oct 30 22:28 network

drwx------
4 root root 4096 Oct 30 22:28 plugins

drwx------
2 root root 4096 Oct 30 22:28 swarm

drwx------
2 root root 4096 Dec 19 20:50 tmp

drwx------
2 root root 4096 Oct 30 22:28 trust

drwx------
2 root root 4096 Oct 30 22:28 volumes

Dockerfile是镜像的描述文件,定义了如何构建Docker镜像。Dockerfile需要到docker网站去查看:

https://hub.docker.com/

查看方法如下:

1 首先在网站上注册一个docker账号

2 在上面的搜索栏中输入hello-world

3 得到仓库中所有关于hello world的镜像,第一个就是我们下载的镜像

4 点击进入后,会发现如下的dockerfile链接

5 点击进入后跳转到github上的链接,可以看到hello-world的dockerfile写法

只有短短三条指令。

      1. FROM scratch
        此镜像是从白手起家,从
        0
        开始构建。

      2. COPY
        hello /
        将文件“hello”复制到镜像的根目录。

      3. CMD
        ["/hello"]
        容器启动时,执行
        /hello

镜像 hello-world 中就只有一个可执行文件 “hello”,其功能就是打印出 “Hello from Docker ......” 等信息。

/hello 就是文件系统的全部内容,连最基本的 /bin,/usr, /lib, /dev 都没有。 而/hello是根据hello.c编译而来的。可以点进去看下hello.c的内容,其实就是打印我们刚才执行docker run hello-world的内容。

docker: docker安装和镜像下载的更多相关文章

  1. 在Ubuntu18.04的Docker中安装Oracle镜像及简单使用

    一.软件环境: 1.OS:Ubuntu 18.04 2.已安装了Docker 二.安装Oracle镜像的过程 1.切换到root账号下,如果是普通账号,下面操作指令前面加sudo 2.搜索oracle ...

  2. Docker的安装和镜像管理并利用Docker容器实现nginx的负载均衡、动静分离

    Docker的安装 一.Docker的概念 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化 ...

  3. docker 的安装和镜像

    一.docker的 安装 : 第一种: yum -y install docker systemctl start docker.service systemctl status docker 第二种 ...

  4. docker 私有仓库上传镜像,其他docker服务器从私有镜像下载

    <pre name="code" class="cpp">docker:/data# docker ps CONTAINER ID IMAGE CO ...

  5. docker核心概念(镜像、容器、仓库)及基本操作

    概要 docker是一种linux容器技术.容器有效的将由单个操作系统挂管理的资源划分到孤立的组中,以便更好的在组之间平衡有冲突的资源使用需求.可简单理解为一种沙盒 .每个容器内运行一个应用,不同的容 ...

  6. CentOS7下Docker的安装与使用

    前言 简介 Docker 是一个开源的应用容器引擎,基于 Go 语言,并遵从 Apache2.0 协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到 ...

  7. docker私服registry管理镜像

    前言 首先试想这样一个场景:当在自己的机器上(docker中)构建了mysql镜像,eureka镜像等等微服务镜像,这些镜像有可能需要放到其他的机器上docker环境中去运行,实行分布式架构部署.但如 ...

  8. CentOS7安装Docker,运行Nginx镜像、Centos镜像

    摘要 总体思路:yum命令直接安装Docker,下载想要的镜像并启动 1.环境,CentOS7 Minimal 64位,Docker必须要64位的系统 2.通过yum命令直接安装,yum instal ...

  9. Docker详细介绍安装与镜像制作和拉取

    一.Docker是什么? 产生背景: 开发和运维之间因为环境不同和导致的矛盾(不同的操作系统.软件环境.应用配置等)DevOps 代码.系统.环境.配置等封装成镜像Image--->运维: 集群 ...

随机推荐

  1. hdu 4503(数学,概率)

    湫湫系列故事——植树节 Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  2. poj 1274(网络流解二分图的最大匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22539   Accepted: 100 ...

  3. BZOJ2243 [SDOI2011]染色(树链剖分+线段树合并)

    题目链接 BZOJ2243 树链剖分 $+$ 线段树 线段树每个节点维护$lc$, $rc$, $s$ $lc$代表该区间的最左端的颜色,$rc$代表该区间的最右端的颜色 $s$代表该区间的所有连续颜 ...

  4. 洛谷——P2527 [SHOI2001]Panda的烦恼

    P2527 [SHOI2001]Panda的烦恼 题目描述 panda是个数学怪人,他非常喜欢研究跟别人相反的事情.最近他正在研究筛法,众所周知,对一个范围内的整数,经过筛法处理以后,剩下的全部都 ...

  5. 网站robots.txt探测工具Parsero

    网站robots.txt探测工具Parsero   robots.txt文件是网站根目录下的一个文本文件.robots.txt是搜索引擎中访问网站的时候要查看的第一个文件.当搜索引擎访问一个站点时,它 ...

  6. Django-自己写的py文件调用models&Non-ASCII character报错&url接收参数

    1.这个设置是网上能查到的最多的,但是没解决我的问题: Django的models.py在外部独立使用,新建一个文件夹,和monitor1目录平级 import sys,os sys.path.app ...

  7. Codeforces 401D Roman and Numbers

    题目大意 Description 给定一个数 N(N<1018) , 求有多少个经过 N 重组的数是 M(M≤100) 的倍数. 注意: ①重组不能有前导零; ②重组的数相同, 则只能算一个数. ...

  8. SpringBoot中@EnableAutoConfiguration注解用法收集

    参考: http://blog.csdn.net/xiaoyu411502/article/details/52770723 https://docs.spring.io/spring-boot/do ...

  9. eclipse不会自动编译的问题解决

    注意:非必要的时候,重新下载eclipse安装是最有效的解决方法. 以下为尝试的步骤: 1.看看project->Build Automatically有没有勾上?如果没有,勾上以后,clean ...

  10. TIdHTTPServer制作REST中间件

    TIdHTTPServer制作REST中间件 使用DELPHI7+INDY9开发 // 陈新光 2017-2-21// LIS数据同步服务器// 浏览器输入:http://127.0.0.1:8000 ...