简介:

Docker是一种容器技术,在微服务领域、云计算领域有着广泛的应用。

Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源。

Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。

容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。

参考教程:http://www.runoob/docker/docker-tutorial.html

组成:

三个组件分别是:

  • Docker Client 是用户界面,它支持用户与Docker Daemon之间通信。
  • Docker Daemon运行于主机上,处理服务请求。
  • Docker Index是中央registry,支持拥有公有与私有访问权限的Docker容器镜像的备份。


三个基本要素分别是:

  • Docker Containers负责应用程序的运行,包括操作系统、用户添加的文件以及元数据。
  • Docker Images是一个只读模板,用来运行Docker容器。
  • DockerFile是文件指令集,用来说明如何自动创建Docker镜像。

应用场景:

  • Web 应用的自动化打包和发布。

  • 自动化测试和持续集成、发布。

  • 在服务型环境中部署和调整数据库或其他的后台应用。

  • 从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境。

安装:

我这里使用的ubuntu,其他操作系统比如:mac、window、centos请参考上面《简介》的参考教程。

本文使用docker库安装,当然ubuntu的库里也有,但是版本可能不是很新,所以我选用docker库安装。

删除apt官方库里的旧版本:

$ sudo apt-get remove docker docker-engine docker-ce docker.io

更新:

$ sudo apt-get update

通过HTTPS使用存储库:

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

添加Docker官方的GPG密钥:

curl -fsSL https://download.docker/linux/ubuntu/gpg | sudo apt-key add -

设置stable存储库:

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker/linux/ubuntu $(lsb_release -cs) stable"

更新

$ sudo apt-get update

安装最新版本的Docker CE:

$ sudo apt-get install -y docker-ce

 

$ sudo docker info
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/info: dial unix /var/run/docker.sock: connect: permission denied

如果没有找到这条命令,则表示Docker安装错误。如果安装正确,会输出类似下面的东西:

Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 2
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-34-generic
Operating System: Ubuntu 18.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.66GiB
Name: huangyinqiang-IIF
ID: BC3A:JF5N:BY23:44TD:KV33:GYL3:QUDV:SGDA:KUW2:PSE4:PTMA:NC6Y
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

 

 

$ sudo systemctl stop docker
$ sudo systemctl start docker
$ sudo systemctl status docker

docker服务的:停止,启动,查看状态:

ok,到此在ubuntu系统中安装docker已经完成!

 

简单的docker使用:

1、docker基础命令:

1、使用 命令行构建一个docker镜像:

sudo docker pull busybox

busybox是linux最小的系统,提供了系统该有的大部分功能。

2、运行一个helloworld的实例

$ sudo docker run busybox /bin/echo Hello Docker
Hello Docker

如果输出如上结果就表示运行成功了!

更多推荐

docker 基础教程-入门:(一)