在 ubuntu docker 容器上运行 apache2 服务器

在 ubuntu docker 容器上运行 apache2 服务器

我正在使用 Ubuntu 14.04。我最近开始学习 docker,我有一个 Ubuntu 14.04 容器。我想在这个容器上安装并运行 apache2,以便在云和服务器中亲自动手。有人能告诉我在特定 IP 地址(带端口号)和 URL 上运行 apache2 服务器的命令吗?

答案1

好的,我认为您对创建与 Apache 一起运行的 Dockerfile 更感兴趣,所以我们开始吧。我提供了使用 PHP 和 MySQL 安装 Apache 的说明。如果您只想要 Apache,请从 apt install 中删除 PHP 和 MYSQL 包。

即使您使用 Ubuntu 14,您也可以使用较新的 Ubuntu 发行版运行 Dockers。我建议使用 Apache 2.4,2.2 已终止使用 (EOL)。

您必须创建一个名为:Dockerfile

FROM ubuntu:19.04

ARG DEBIAN_FRONTEND=noninteractive

# That is not needed
# RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf

RUN echo "Europe/Ireland" | tee /etc/timezone

# Note: You should install everything in a single line concatenated with
#       && and finalising with apt autoremove && apt clean
#       in order to save the maximum space on the layer.

#       In order to use the less space possible, as every command is a layer
RUN apt-get update && apt-get install -y apache2 ntpdate libapache2-mod-php7.2 \
mysql-server php7.2-mysql php-dev libmcrypt-dev php-pear git && \
apt autoremove && apt clean

# Enable mod rewrite. Optional, required for CMS like WordPress to rewrite urls
RUN a2enmod rewrite

EXPOSE 80

CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

然后您将在同一目录中执行以下操作:

sudo docker build -t trinity .

并运行它:

sudo docker run -d -p 80:80 trinity

如果需要交互输入:

sudo docker exec -i -t trinity /bin/bash

答案2

使用 Docker 启动 Apache 网络服务器是一项非常简单的任务。

在开始之前,我建议你先阅读以下指南,它们对于理解 Docker 入门步骤非常有用 -运行简单应用程序快速启动容器

关于你的 Apache 问题:我建议你遵循这个,您可以在其中找到一些有关如何在 Docker 上运行 Apache 网络服务器的有用建议。

如果你想在某个特定端口上运行 Docker 容器,你可以从以下操作开始 -Docker 网络指南

祝你好运!

答案3

尝试:apt-get update && apt-get install apache2 -y

--> 这是因为 docker 没有存储应用程序存储库缓存

相关内容