【发布时间】:2014-05-21 16:52:45
【问题描述】:
我似乎无法访问在我的 Mac 上本地运行的简单 Docker 容器。我可以从容器中运行 curl localhost 并看到默认的 Apache 页面已提供,但我无法从机器的浏览器中点击它。
我想知道我是否有 VirtualBox 配置问题或其他问题。对诊断问题有帮助吗?
Dockerfile
# Build the image of ubuntu 12.04 LTS
from ubuntu:precise
# Run apt-get update
run apt-get -y update
# Install LAMP
run DEBIAN_FRONTEND=noninteractive apt-get -y install lamp-server^
run apt-get -y install vim-tiny curl wget
# Put custom scripts in the container and give proper permissions to them
add ./startup.sh /usr/local/bin/startup.sh
run chmod 755 /usr/local/bin/startup.sh
add site.vhost /etc/apache2/sites-available/site
run a2ensite site
# Expose port 80 to the host machine
expose 80
site.vhost
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
#Order allow,deny allow from all
</Directory>
# Possible values include: debug, info, notice, warn, error, crit, # alert, emerg.
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
startup.sh
#!/bin/bash
a2dissite default
apache2ctl graceful
/usr/bin/mysqld_safe &
开始...
我将使用docker build -t test1 . 构建图像 - 这似乎运行良好。
在初始设置时,我运行 docker run -d -v $(pwd)/mysql:/tmp/mysql test1 /bin/bash -c "cp -rp /var/lib/mysql/* /tmp/mysql" 来设置 MySQL。
然后我运行docker run -i -t -v $(pwd)/mysql:/var/lib/mysql -v $(pwd)/www:/var/www -p 8080:80 test1 /bin/bash 来启动实际实例。
到达终端后,我运行service apache2 start,一切似乎都运行良好。如果我运行curl localhost,我会得到默认页面就好了。
一切似乎都很好,只是从主机上打它不起作用。我应该能够导航到 http://127.0.0.1:8080 并将其转发到端口 80 上的容器,对吧?
【问题讨论】: