1、 进入ubuntu 命令台
docker exec -it ubuntu /bin/bash
2、首次使用先更新下
apt update
3、安装apache
目前的ubuntu里不支持Apache,支持的是Apache2
apt install apache2
4、启动apache
service apache2 start
这里看到它报了一个提示
- Starting Apache httpd web server apache2 AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.XX.XX.XX. Set the ‘ServerName’ directive globally to suppress this message
5、解决上面的报错
如果vim没有的话需要先安装vim (apt install vim)
vim /etc/apache2/apache2.conf
在最后一行加上ServerName 127.0.0.1
如图
apachectl configtest
重启可以发现没报错了
6、重新以指定端口、后台重新启用镜像
docker run -itd --name ubuntu -p 8070:80 -d ubuntu
7、验证外部是否可以访问apache
在浏览器输入你的ip:prot,比如
http://119.29.100.01:8070/
显示下面的页面就表示Apache配置正常