我已经用Flask构建了一个后端Web应用程序。 CMD
的{{1}}行运行Dockerfile
,内部调用python app.py
,因此该应用程序在docker容器中在app.run(host='0.0.0.0')
上运行。然后,我使用以下命令运行构建的容器
0.0.0.0:5000
前端是用ember构建的。在$ docker run -p 5000:5000 -it my-image:latest
文件中,.ember-cli
设置为proxy
。当我在本地运行http://localhost:5000
时,该应用程序在$ ember serve
上平稳运行,并与从docker映像运行的后端进行通信。但是,我也想在docker映像(基于apache映像)上运行前端。我的Dockerfile:
localhost:4200
FROM httpd:2.4-alpine
COPY ./dist/ /usr/local/apache2/htdocs/
COPY ./.htaccess /usr/local/apache2/htdocs/
文件是直接从Ember - Deploying复制的(根据.htaccess
部分):
Servers
然后我执行以下操作:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [L]
</IfModule>
然后我转到$ ember b --prod # build the app for production (stored in ./dist/)
$ docker build -t my-frontend:latest .
$ docker run -dit --name my-frontend -p 8080:80 my-frontend:latest
,可以看到我的应用程序的加载轮,这意味着该图像正在单独工作。但是,当我尝试访问后端时,我仍然收到404错误。
容器彼此之间无法通信,我在做什么错了?