apache docker容器与rstudio容器通信
我最近一直在玩弄docker和apache,我对它们都不是很了解 我在同一主机上的两个docker容器之间存在通信问题 一个容器正在运行带有选项-p80:80的apache。 转到localhost:80显示默认的apache页面 我有第二个容器运行带有选项-p 8787:8787的rocker/rstudio图像。 转到localhost:8787将按预期显示rstudio登录页面 我希望在apache容器中使localhost/rstudio将我带到在rocker容器中运行的rstudio的登录页面 据我所知,apache容器应该能够看到localhost:8787,在可用站点下,我有以下rstudio.conf文件apache docker容器与rstudio容器通信,apache,docker,rstudio-server,Apache,Docker,Rstudio Server,我最近一直在玩弄docker和apache,我对它们都不是很了解 我在同一主机上的两个docker容器之间存在通信问题 一个容器正在运行带有选项-p80:80的apache。 转到localhost:80显示默认的apache页面 我有第二个容器运行带有选项-p 8787:8787的rocker/rstudio图像。 转到localhost:8787将按预期显示rstudio登录页面 我希望在apache容器中使localhost/rstudio将我带到在rocker容器中运行的rstudio的
<VirtualHost *:80>
<Proxy *>
Allow from localhost
</Proxy>
# Specify path for Logs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Following lines should open rstudio directly from the url
# Map rstudio to rstudio/
RedirectMatch ^/rstudio$ /rstudio/
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /rstudio/(.*) ws://localhost:8787/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /rstudio/(.*) http://localhost:8787/$1 [P,L]
ProxyPass /rstudio/ http://localhost:8787/
ProxyPassReverse /rstudio/ http://localhost:8787/
ProxyRequests off
</VirtualHost>
允许从本地主机
#指定日志的路径
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
重新启动发动机
#以下行应直接从url打开rstudio
#将rstudio映射到rstudio/
重定向匹配^/rstudio$/rstudio/
RewriteCond%{HTTP:Upgrade}=websocket
重写规则/rstudio/(*)ws://localhost:8787/$1[P,L]
重写cond%{HTTP:Upgrade}=网袋
重写规则/rstudio/(*)http://localhost:8787/$1[P,L]
ProxyPass/rstudio/http://localhost:8787/
ProxyPassReverse/rstudio/http://localhost:8787/
代理请求关闭
按照rstudio服务器配置文档的建议。但是localhost:80/rstudio返回404,我不明白为什么。有人对如何解决这个问题有什么建议吗
我希望从apache容器内部执行此操作,而不仅仅是在rocker容器中安装apache的主要原因是,apache容器也可以管理其他连接的容器
据我所知,apache容器应该能够看到localhost:8787,在可用站点下,我有以下rstudio.conf文件
<VirtualHost *:80>
<Proxy *>
Allow from localhost
</Proxy>
# Specify path for Logs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Following lines should open rstudio directly from the url
# Map rstudio to rstudio/
RedirectMatch ^/rstudio$ /rstudio/
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /rstudio/(.*) ws://localhost:8787/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /rstudio/(.*) http://localhost:8787/$1 [P,L]
ProxyPass /rstudio/ http://localhost:8787/
ProxyPassReverse /rstudio/ http://localhost:8787/
ProxyRequests off
</VirtualHost>
差不多。从apache docker容器内部看,localhost是该容器,而不是主机
如果您想了解我在说什么,请进入正在运行的apache容器并curl localhost:8787
。你会得到一个404。现在在apache容器中为8787添加另一个vhost并启用它,然后从容器内部再次获得新vhost的内容
两个最简单的选项是定制网络或使用docker compose
自定义网络
docker network create jamie-rowan-network
docker run -itd -p 80:80 --network jamie-rowan-network --name apache <image>
docker run -itd -p 8787:8787 --network jamie-rowan-network --name rstudio <image>
这将实现与自定义网络相同的功能;rstudio可以通过apache容器通过
curl rstudio:8787
访问,反之,可以通过rstudio通过curl apache:80
访问apache,感谢您的快速回答。我也一直在胡闹作曲。没有意识到它也建立了一个网络结构。我现在还不确定,但很快就会尝试你的答案。好的,所以我修改了我的docker作文,使它看起来与上面的相似。我确实可以连接到apache容器并curl rstudio:8787
并获得响应(不受支持的浏览器,但不是什么都没有)。这会让我觉得在rstudio.conf中,localhost:8787被替换为rstudio:8787
,然后web浏览器中的localhost:80/rstudio应该会显示我想要的内容,但我仍然得到404。我遗漏了什么吗?我会怀疑rstudio.conf或其他httpd中有什么东西。您确定httpd正在接收您的配置文件吗?