Docker运行简单的web服务——httpd helloworld目录【阅读时间:约5分钟】

  • 一、Docker简介
  • 二、Docker的安装与配置【CentOS环境】
  • 三、Docker运行简单的web服务——httpd helloworld
  • 四、References

一、Docker简介

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。


观察Docker图标,其实很形象的解释了什么是Docker。在没有使用集装箱的情况下,我们需要考虑不同形状、尺寸的货物怎么安放,货物与货物之间是否能堆叠,这无疑是很繁琐的事情。现在有了集装箱(容器),我们就能将不同的货物放入集装箱之内这样就能以同样的方式来存放货物,实现了标准化。

Docker采用了集装箱原理,我们将程序放入到容器中,实现“一次封装,到处运行”,只要开发环境能跑,在其他任何流行的机器上都能运行。并且将程序丢入到容器中,很好的实现了程序与程序之间的隔离,避免了类似Java开发的程序和.net开发的程序安装在一个服务器上需要很多调试,有时还会产生冲突的情况。

Docker的应用场景:

Web 应用的自动化打包和发布。
自动化测试和持续集成、发布。
在服务型环境中部署和调整数据库或其他的后台应用。
从头编译或者扩展现有的 OpenShift 或 Cloud Foundry 平台来搭建自己的 PaaS 环境。

二、Docker的安装与配置【CentOS环境】

基本安装过程,请参考我之前的一篇博客:博客

由于docker pull会出现timeout error的情况,一般需要更换docker镜像源为国内的镜像源,请参考我之前的一篇博客:博客

三、Docker运行简单的web服务——httpd helloworld

在之前我们曾经使用Docker运行过一个最简单的helloworld映像:


[root@localhost henryhzy]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latestHello 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.(amd64)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/

而最近在学习web和docker的相关操作,因此想顺便尝试一下简单的web服务,这里我使用docker Apache与httpd。

首先安装Apache与httpd:

[root@localhost henryhzy]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
6ec7b7d162b2: Already exists
17e233bac21e: Pulling fs layer
130aad5bf43a: Pulling fs layer
81d0a34533d4: Pulling fs layer
da240d12a8a4: Waiting
latest: Pulling from library/httpd
6ec7b7d162b2: Already exists
17e233bac21e: Pull complete
130aad5bf43a: Pull complete
81d0a34533d4: Pull complete
da240d12a8a4: Pull complete
Digest: sha256:a3a2886ec250194804974932eaf4a4ba2b77c4e7d551ddb63b01068bf70f4120
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest

查看镜像版本:

[root@localhost henryhzy]# docker images httpd
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
httpd        latest    dd85cdbb9987   10 days ago   138MB
[root@localhost henryhzy]#

运行镜像如下:

docker run -itd \
--name test_web_server \
-p 8085:80 \
-v /home/user/website/:/usr/local/apache2/htdocs/ \
httpd:latest

-p 8085:80,意思是端口号的映射,<host_port>:<容器内apache的port>

-v /home/user/website/:/usr/local/apache2/htdocs/, 这是docker重要的volume的概念。<host_路径>:<容器内的路径>。

查看docker容器确认httpd已启动:

docker ps

此时访问 http://<YOUR_IP>:8085即可到达一个web page

在apache的folder里面放一个编写好的网页,之后就可以通过这个端口8085来访问,由此便完成了安装Apache与运行简单的web服务的流程。

下面给出一个具体的helloworld网页的例子,在你的host,到/home/user/website/文件夹下,建立一个helloworld.html网页,这个文件会自动映射到容器内的/usr/local/apache2/htdocs/下,被apache发布出来。

cd /home/user/website
vi helloworld.html

helloworld.html内容如下:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>hello world web page</title>
</head>
<body><h1>Hello from HenryHZY 18342026!</h1>
</body>
</html>

然后保存,访问 http://<YOUR_IP>:8085/helloworld.html

大体步骤如上,just enjoy it~

四、References

  1. Docker 安装 Apache
  2. Docker Apache建一個hello world的Web

Docker安装Apache与运行简单的web服务——httpd helloworld相关推荐

  1. 1-3.Win10系统利用Pycharm社区版安装Django搭建一个简单Python Web项目的步骤之三

    在1-1.Win10系统利用Pycharm社区版安装Django搭建一个简单Python Web项目的步骤之一 基础上进行如下操作: 所有路由不能全部都在myDjango下的urls.py路由文件中, ...

  2. 使用docker安装gitlab以及gitlab简单使用

    使用docker安装gitlab以及gitlab简单使用 docker 安装gitlab以及使用 1.创建主机映射目录 2.gitlab镜像拉取 3.运行gitlab镜像 4.配置 5.配置ssl支持 ...

  3. 2022年Docker安装Apache Airflow2.2分布式任务调度框架

    目录 一.Apache Airflow介绍 二.下载Airflow官方的docker-compose.yaml文件 三.开始安装 四.启动Apache Airflow 五.访问系统 六.Airflow ...

  4. [WS]使用Axis发布简单的Web服务

    使用Axis,要发布一个Web服务非常简单,简直不能再简单了,尽管看起来过程和相关代码有些长.我这个帖子里用到了这些软件:Axis 1.1.Eclipse 2.1和Eclipse的Tomcat插件2. ...

  5. 警告 初始化默认驱动器时出错“找不到运行 Active Directory Web 服务的默认服务器。”...

    在导入AD模块时报错如下 "警告 初始化默认驱动器时出错"找不到运行 Active Directory Web 服务的默认服务器." 报错的是web服务器,第一时间想到的 ...

  6. centos7 docker删除端口映射_centos7安装docker,结合docker安装mysql,学习简单使用

    需要快速安装centos7的可以结合上一遍文章vagrant结合virtualbox让你直接在cmd窗口操作linux系统centos7 地址:https://www.toutiao.com/i685 ...

  7. redis docker安装、进入命令行后启动服务

    下载redis镜像 首先查看一下redis是否正确: docker search redis 显示: NAME DESCRIPTION STARS OFFICIAL AUTOMATED redis R ...

  8. 通过docker部署一个简单的web服务

    前面把redis.oracle都部署好了,还有最后两步: 1)docker镜像制作和启动 2)redis和oracle都在vitualbox中,防火墙问题等等 docker 镜像及制作 首先安装好do ...

  9. 1-2.Win10系统利用Pycharm社区版安装Django搭建一个简单Python Web项目的步骤之二

    七.在项目下新建 templates 路径 在工程上,右键,添加templates目录 注意*: 此目录下即用来存放我们的html文件: 此目录一般是与app的主目录是平级的.当然也可以建立在app的 ...

最新文章

  1. JS-匀速运动-运动停止
  2. Android模块化面向接口编程,讲的明明白白!
  3. navicat 连接 mogodb 报错 requires authentication
  4. python3安装步骤mac-Mac安装Python3
  5. 感谢球,感谢铁道部,感谢电信,我终于定到回武汉的票了
  6. 对5种主流编程语言的吐槽
  7. P1496 vijos1165-火烧赤壁【离散化】
  8. webhooks php,GitHub和WebHooks自动部署PHP项目
  9. 从语音识别到语义识别,中间还有多长的路要走?-模拟/电源-与非网
  10. 【路径规划】基于matlab蚁群算法机器人栅格地图路径规划【含Matlab源码 119期】
  11. 了解STM32的内部FLASH空间
  12. 使用STVP解除STM32flash读出保护
  13. C++ QT开发人机象棋(棋子走法)
  14. linux 帝国cms 刷新,帝国cms怎么自动刷新网站首页?(帝国CMS自动刷新首页的方法)...
  15. 实现编辑网页document.body.contentEditable
  16. Arcgis api for JavaScript 4.12解读-----symbol
  17. How to covert HEIF to JPG with Java
  18. 如何解决不能绘制网络模型,报错protobuf
  19. 比较超声与临床体检检查早期关节炎患者手部屈肌腱腱鞘炎
  20. BZOJ1064【NOI2008】【假面舞会】

热门文章

  1. 2022-2028年中国基金业投资分析及前景预测报告
  2. 2022-2028年中国农副产品行业市场供需规模及未来前景分析报告
  3. 【Spring】spring基于纯注解的声明式事务控制
  4. dataframe重命名
  5. 在idea使用maven工程建立web项目时,启动Tomcat访问不到项目首页。
  6. LeetCode简单题之二分查找
  7. 2021年大数据ELK(二十):FileBeat是如何工作的
  8. 2021年大数据Hadoop(三十):Hadoop3.x的介绍
  9. 快速android app开发,快速學會開發 Android App
  10. python正确方法,方法 - 廖雪峰的官方网站