docker里安裝ubuntu


使用 Ubuntu 官方鏡像

Ubuntu 相關的鏡像有很多,這里使用 -s 10 參數,只搜索那些被收藏 10 次以上的鏡像

$ docker search -s 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]
ansible/ubuntu14.04-ansible          Ubuntu 14.04 LTS with ansible                   15                   [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]

注意,Docker 1.12 版本中已經不支持 --stars 參數,則可以使用 -f stars=N 參數。

根據搜索出來的結果,讀者可以自行選擇下載鏡像並使用。

下面以 ubuntu 14.04 為例,演示如何使用該鏡像安裝一些常用軟件。

首先使用 -ti 參數啟動容器,登錄 bash,查看 ubuntu 的發行版本號。

 

Ubuntu

基本信息

Ubuntu 是流行的 Linux 發行版,其自帶軟件版本往往較新一些。

該倉庫位於 https://hub.docker.com/_/ubuntu/ ,提供了 Ubuntu 從 12.04 ~ 16.10 各個版本的鏡像。

使用方法

默認會啟動一個最小化的 Ubuntu 環境。

$ docker run --name some-ubuntu -i -t ubuntu
root@523c70904d54:/#

當試圖直接使用 apt-get 安裝一個軟件的時候,會提示 E: Unable to locate package

1 root@7d93de07bf76:/# apt-get install curl
2 Reading package lists... Done
3 Building dependency tree
4 Reading state information... Done
5 E: Unable to locate package curl

這並非系統不支持 apt-get 命令。Docker 鏡像在制作時為了精簡清除了 apt 倉庫信息,因此需要先執行 apt-get update 命令來更新倉庫信息。更新信息后即可成功通過 apt-get 命令來安裝軟件。

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 工具。

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 服務。

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 來測試本地訪問。

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 參數對外映射服務端口,可以允許容器外來訪問該服務。

相關資源


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM