# Debian Ubuntu
`Debian` 和 `Ubuntu` 都是目前較為流行的 **Debian 系** 的服務器操作系統,十分適合研發場景。`Docker Hub` 上提供了官方鏡像,國內各大容器云服務也基本都提供了相應的支持。
## Debian 系統簡介

`Debian` 是由 `GPL` 和其他自由軟件許可協議授權的自由軟件組成的操作系統,由 **Debian 計劃(Debian Project)** 組織維護。**Debian 計劃** 是一個獨立的、分散的組織,由 `3000` 人志愿者組成,接受世界多個非盈利組織的資金支持,`Software in the Public Interest` 提供支持并持有商標作為保護機構。`Debian` 以其堅守 `Unix` 和自由軟件的精神,以及其給予用戶的眾多選擇而聞名。現時 `Debian` 包括了超過 `25,000` 個軟件包并支持 `12` 個計算機系統結構。
`Debian` 作為一個大的系統組織框架,其下有多種不同操作系統核心的分支計劃,主要為采用 `Linux` 核心的 `Debian GNU/Linux` 系統,其他還有采用 `GNU Hurd` 核心的 `Debian GNU/Hurd` 系統、采用 `FreeBSD` 核心的 `Debian GNU/kFreeBSD` 系統,以及采用 `NetBSD` 核心的 `Debian GNU/NetBSD` 系統。甚至還有利用 `Debian` 的系統架構和工具,采用 `OpenSolaris` 核心構建而成的 `Nexenta OS` 系統。在這些 `Debian` 系統中,以采用 `Linux` 核心的 `Debian GNU/Linux` 最為著名。
眾多的 `Linux` 發行版,例如 `Ubuntu`、`Knoppix` 和 `Linspire` 及 `Xandros` 等,都基于 `Debian GNU/Linux`。
### 使用 Debian 官方鏡像
讀者可以使用 `docker search` 查找 `Debian` 鏡像:
```bash
$ docker search debian
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
debian Debian is... 1565 [OK]
neurodebian NeuroDebian... 26 [OK]
armbuild/debian port of debian 8 [OK]
...
```
官方提供了大家熟知的 `debian` 鏡像以及面向科研領域的 `neurodebian` 鏡像。
可以使用 `docker run` 直接運行 `Debian` 鏡像。
```bash
$ docker run -it debian bash
root@668e178d8d69:/# cat /etc/issue
Debian GNU/Linux 8
```
`Debian` 鏡像很適合作為基礎鏡像,構建自定義鏡像。
## Ubuntu 系統簡介

`Ubuntu` 是一個以桌面應用為主的 `GNU/Linux` 操作系統,其名稱來自非洲南部祖魯語或豪薩語的“ubuntu”一詞(官方譯名“友幫拓”,另有“吾幫托”、“烏班圖”、“有奔頭”或“烏斑兔”等譯名)。`Ubuntu` 意思是“人性”以及“我的存在是因為大家的存在”,是非洲傳統的一種價值觀,類似華人社會的“仁愛”思想。 `Ubuntu` 基于 `Debian` 發行版和 `GNOME/Unity` 桌面環境,與 `Debian` 的不同在于它每 6 個月會發布一個新版本,每 2 年推出一個長期支持 **(Long Term Support,LTS)** 版本,一般支持 3 年時間。
### 使用 Ubuntu 官方鏡像
`Ubuntu` 相關的鏡像有很多,這里使用 `--filter=stars=10` 參數,只搜索那些被收藏 `10` 次以上的鏡像。
```bash
$ docker search --filter=stars=10 ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Official Ubuntu base image 840 [OK]
dockerfile/ubuntu Trusted automated Ubuntu (http://www.ubunt... 30 [OK]
crashsystems/gitlab-docker A trusted, regularly updated build of GitL... 20 [OK]
sylvainlasnier/memcached This is a Memcached 1.4.14 docker images b... 16 [OK]
ubuntu-upstart Upstart is an event-based replacement for ... 16 [OK]
mbentley/ubuntu-django-uwsgi-nginx 16 [OK]
clue/ttrss The Tiny Tiny RSS feed reader allows you t... 14 [OK]
dockerfile/ubuntu-desktop Trusted automated Ubuntu Desktop (LXDE) (h... 14 [OK]
tutum/ubuntu Ubuntu image with SSH access. For the root... 12 [OK]
```
根據搜索出來的結果,讀者可以自行選擇下載鏡像并使用。
下面以 `ubuntu:18.04` 為例,演示如何使用該鏡像安裝一些常用軟件。
首先使用 `-ti` 參數啟動容器,登錄 `bash`,查看 `ubuntu` 的發行版本號。
```bash
$ docker run -ti ubuntu:18.04 /bin/bash
root@7d93de07bf76:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
```
當試圖直接使用 `apt-get` 安裝一個軟件的時候,會提示 `E: Unable to locate package`。
```bash
root@7d93de07bf76:/# apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package curl
```
這并非系統不支持 `apt-get` 命令。Docker 鏡像在制作時為了精簡清除了 `apt` 倉庫信息,因此需要先執行 `apt-get update` 命令來更新倉庫信息。更新信息后即可成功通過 `apt-get` 命令來安裝軟件。
```bash
root@7d93de07bf76:/# apt-get update
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
Ign http://archive.ubuntu.com trusty-security InRelease
Ign http://archive.ubuntu.com trusty-proposed InRelease
Get:1 http://archive.ubuntu.com trusty Release.gpg [933 B]
...
```
首先,安裝 `curl` 工具。
```bash
root@7d93de07bf76:/# apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
ca-certificates krb5-locales libasn1-8-heimdal libcurl3 libgssapi-krb5-2
libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal
libheimntlm0-heimdal libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1
libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2
libroken18-heimdal librtmp0 libsasl2-2 libsasl2-modules libsasl2-modules-db
libwind0-heimdal openssl
...
root@7d93de07bf76:/# curl
curl: try 'curl --help' or 'curl --manual' for more information
```
接下來,再安裝 `apache` 服務。
```bash
root@7d93de07bf76:/# apt-get install -y apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2-bin apache2-data libapr1 libaprutil1 libaprutil1-dbd-sqlite3
libaprutil1-ldap libxml2 sgml-base ssl-cert xml-core
...
```
啟動這個 `apache` 服務,然后使用 `curl` 來測試本地訪問。
```bash
root@7d93de07bf76:/# service apache2 start
* Starting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
*
root@7d93de07bf76:/# curl 127.0.0.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
Modified from the Debian original for Ubuntu
Last updated: 2014-03-19
See: https://launchpad.net/bugs/1288690
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Apache2 Ubuntu Default Page: It works</title>
<style type="text/css" media="screen">
...
```
配合使用 `-p` 參數對外映射服務端口,可以允許容器外來訪問該服務。
## 相關資源
* `Debian` 官網:[https://www.debian.org/](https://www.debian.org/)
* `Neuro Debian` 官網:[http://neuro.debian.net/](http://neuro.debian.net/)
* `Debian` 官方倉庫:[https://github.com/Debian](https://github.com/Debian)
* `Debian` 官方鏡像:[https://hub.docker.com/\_/debian/](https://hub.docker.com/_/debian/)
* `Debian` 官方鏡像倉庫:[https://github.com/tianon/docker-brew-debian/](https://github.com/tianon/docker-brew-debian/)
* `Ubuntu` 官網:[http://www.ubuntu.org.cn/global](http://www.ubuntu.org.cn/global)
* `Ubuntu` 官方倉庫:[https://github.com/ubuntu](https://github.com/ubuntu)
* `Ubuntu` 官方鏡像:[https://hub.docker.com/\_/ubuntu/](https://hub.docker.com/_/ubuntu/)
* `Ubuntu` 官方鏡像倉庫:[https://github.com/tianon/docker-brew-ubuntu-core](https://github.com/tianon/docker-brew-ubuntu-core)
- 前言
- Docker 簡介
- 什么是 Docker
- 為什么要用 Docker
- 基本概念
- 鏡像
- 容器
- 倉庫
- 安裝 Docker
- Ubuntu
- Debian
- Fedora
- CentOS
- Raspberry Pi
- macOS
- Windows 10
- 鏡像加速器
- 使用鏡像
- 獲取鏡像
- 列出鏡像
- 刪除本地鏡像
- 利用 commit 理解鏡像構成
- 使用 Dockerfile 定制鏡像
- Dockerfile 指令詳解
- COPY 復制文件
- ADD 更高級的復制文件
- CMD 容器啟動命令
- ENTRYPOINT 入口點
- ENV 設置環境變量
- ARG 構建參數
- VOLUME 定義匿名卷
- EXPOSE 暴露端口
- WORKDIR 指定工作目錄
- USER 指定當前用戶
- HEALTHCHECK 健康檢查
- ONBUILD 為他人作嫁衣裳
- 參考文檔
- Dockerfile 多階段構建
- 實戰多階段構建 Laravel 鏡像
- 構建多種系統架構支持的 Docker 鏡像
- 使用 BuildKit 構建鏡像
- 其它制作鏡像的方式
- 實現原理
- 操作容器
- 啟動
- 守護態運行
- 終止
- 進入容器
- 導出和導入
- 刪除
- 訪問倉庫
- Docker Hub
- 私有倉庫
- 私有倉庫高級配置
- Nexus 3
- 數據管理
- 數據卷
- 掛載主機目錄
- 使用網絡
- 外部訪問容器
- 容器互聯
- 配置 DNS
- 高級網絡配置
- 快速配置指南
- 容器訪問控制
- 端口映射實現
- 配置 docker0 網橋
- 自定義網橋
- 工具和示例
- 編輯網絡配置文件
- 實例:創建一個點到點連接
- Docker 三劍客之 Compose 項目
- 簡介
- 安裝與卸載
- 使用
- 命令說明
- Compose 模板文件
- 實戰 Django
- 實戰 Rails
- 實戰 WordPress
- Docker 三劍客之 Machine 項目
- 安裝
- 使用
- Docker 三劍客之 Docker Swarm
- Swarm mode
- 基本概念
- 創建 Swarm 集群
- 部署服務
- 使用 compose 文件
- 管理密鑰
- 管理配置信息
- 滾動升級
- 安全
- 內核命名空間
- 控制組
- 服務端防護
- 內核能力機制
- 其它安全特性
- 總結
- 底層實現
- 基本架構
- 命名空間
- 控制組
- 聯合文件系統
- 容器格式
- 網絡
- Etcd 項目
- 簡介
- 安裝
- 集群
- 使用 etcdctl
- CoreOS 項目
- 簡介
- 工具
- Kubernetes 項目
- 簡介
- 快速上手
- 基本概念
- kubectl 使用
- 架構設計
- Mesos - 優秀的集群資源調度平臺
- Mesos 簡介
- 安裝與使用
- 原理與架構
- Mesos 配置項解析
- 日志與監控
- 常見應用框架
- 本章小結
- 容器與云計算
- 簡介
- 亞馬遜云
- 騰訊云
- 阿里云
- 小結
- 實戰案例-操作系統
- Busybox
- Alpine
- Debian Ubuntu
- CentOS Fedora
- 本章小結
- 實戰案例-CI/CD
- GitHub Actions
- Drone
- 部署 Drone
- Travis CI
- Docker 開源項目
- LinuxKit
- 附錄
- 附錄一:常見問題總結
- 附錄二:熱門鏡像介紹
- Ubuntu
- CentOS
- Nginx
- PHP
- Node.js
- MySQL
- WordPress
- MongoDB
- Redis
- 附錄三:Docker 命令查詢
- 附錄四:Dockerfile 最佳實踐
- 附錄五:如何調試 Docker
- 附錄六:資源鏈接