Ubuntu是以桌面应用为主的GUN/Linux开源操作系统,其名称来自于非洲南部祖鲁语或豪萨语的“ubuntu”一词。官方译名为“友帮拓”,另有“乌班图”等译名。Ubuntu每6个月发布一个新版本,每两年推出一个长期支持(Long Term Support ,LTS)版本,一般支持3年时间。
Ubuntu相关的镜像有很多,这里之搜索哪些评星50以上的镜像:
以ubuntu18.04为例,安装一些常用的软件:
$ docker run -it ubuntu:18.04 bash
root@878cacc2bb7f:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
执行apt-get update命令更新仓库信息,更新信息后即可成功通过apt-get命令来安装软件:
root@878cacc2bb7f:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [116 kB]
...
安装curl工具
root@878cacc2bb7f:/# apt-get install curl
Reading package lists... Done
root@878cacc2bb7f:/# curl
curl: try 'curl --help' or 'curl --manual' for more information
接下来,再安装Apache服务:
root@878cacc2bb7f:/# apt-get install apache2
启动这个Apche服务,然后使用curl工具测试本地访问:
root@878cacc2bb7f:/# service apache2 start
查看进程
root@878cacc2bb7f:/# top
top - 15:20:51 up 7:48, 0 users, load average: 0.00, 0.01, 0.05
Tasks: 5 total, 1 running, 4 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 6154100 total, 3638084 free, 496456 used, 2019560 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 5343748 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 18492 2060 1636 S 0.0 0.0 0:00.03 bash
3345 root 20 0 73948 2624 1416 S 0.0 0.0 0:00.00 apache2
3348 www-data 20 0 1280616 4352 776 S 0.0 0.1 0:00.00 apache2
3349 www-data 20 0 1280616 4352 776 S 0.0 0.1 0:00.00 apache2
3407 root 20 0 36608 1712 1276 R 0.0 0.0 0:00.00 top
使用curl测试
root@878cacc2bb7f:/# curl http://localhost:80
<!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: 2016-11-16
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">
* {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
配合使用-p参数对外映射服务端口,可以允许容器外来访问该服务。
1.使用commit提交为一个镜像
$ docker commit 878cacc2bb7f ubuntu:apache2
sha256:973333ac9cdcf6f84d9183ee0e826640e66670ae16425b26f8e273b00c09accd
- 使用-p 映射出去
[root@c7-45 debian]# docker run --name apach2 -itd -p 80:80 ubuntu:apache2
b8490a17c82acb8256b1dbb3c2b72c527d174434b0569ed01dd80a1a5307bae7
[root@c7-45 debian]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8490a17c82a ubuntu:apache2 "bash" 3 seconds ago Up 1 second 0.0.0.0:80->80/tcp apach2
查看端口
[root@c7-45 debian]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::80 :::* LISTEN 12345/docker-proxy
现在去访问web界面是拒绝的(求解 知道的可以打在评论区)
1.进入容器查看服务
[root@c7-45 debian]# docker exec -it b8 bash
#服务未启动
root@b8490a17c82a:/# top
top - 15:25:32 up 7:53, 0 users, load average: 0.00, 0.01, 0.05
Tasks: 3 total, 1 running, 2 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 6154100 total, 3423888 free, 496368 used, 2233844 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 5341484 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 18496 1800 1472 S 0.0 0.0 0:00.01 bash
15 root 20 0 18488 2000 1588 S 0.0 0.0 0:00.01 bash
26 root 20 0 36608 1712 1276 R 0.0 0.0 0:00.00 top
2.启动服务并查看进程
root@b8490a17c82a:/# service apache2 start
* Starting Apache httpd web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
*
root@b8490a17c82a:/# top
top - 15:29:52 up 7:57, 0 users, load average: 0.00, 0.01, 0.05
Tasks: 6 total, 1 running, 5 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 6154100 total, 3406648 free, 513164 used, 2234288 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 5324404 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 18496 1800 1472 S 0.0 0.0 0:00.01 bash
15 root 20 0 18488 2008 1592 S 0.0 0.0 0:00.01 bash
56 root 20 0 73948 2668 1456 S 0.0 0.0 0:00.01 apache2
60 www-data 20 0 1280696 11088 1296 S 0.0 0.2 0:00.00 apache2
61 www-data 20 0 1280648 4612 1016 S 0.0 0.1 0:00.00 apache2
119 root 20 0 36608 1720 1276 R 0.0 0.0 0:00.04 top
3.访问web界面
4.退出容器 后服务正常启动(不影响使用 但是多了一个步骤 有知道的大神 可以告知下)
Ubuntu 的相关资源如下:
Ubuntu官网:http://www.ubuntu.org.cn/global
Ubuntu官方镜像:https://hub.docker.com/_/ubuntu/