我对 Docker、Ghost 和 node 真的很陌生,所以请原谅这里的任何明目张胆的无知。
我正在尝试根据映像为 Ghost 设置 Docker 映像/容器google/nodejs-runtime
,但是当我通过 Docker 运行时无法连接到服务器。
一些细节:我在 OS X 上,所以我使用的是 boot2docker。我将 Ghost 作为 npm 模块运行,配置为使用端口 8080,因为这是google/nodejs-runtime
预期的。当我使用npm start
. 我还在端口 8080 上尝试了一个简单的“Hello, World” Express 应用程序,它可以在 Docker 中运行。
我的目录结构如下所示:
- 我的应用
- 内容/
- Dockerfile
- ghost_config.js
- 包.json
- 服务器.js
package.json
{
"name": "my_app",
"private": true,
"dependencies": {
"ghost": "0.5.2",
"express": "3.x"
}
}
Dockerfile
FROM google/nodejs-runtime
ghost_config.js
我将所有出现的端口 2368 更改为 8080。
server.js
// This Ghost server works with npm start, but not with Docker
var ghost = require('ghost');
var path = require('path');
ghost({
config: path.join(__dirname, 'ghost_config.js')
}).then(function (ghostServer) {
ghostServer.start();
});
// This "Hello World" app works in Docker
// var express = require('express');
// var app = express();
// app.get('/', function(req, res) {
// res.send('Hello World');
// });
// var server = app.listen(8080, function() {
// console.log('Listening on port %d', server.address().port);
// });
我使用 构建我的 Docker 映像docker build -t my_app .
,然后使用 运行它docker run -p 8080 my_app
,这会将其打印到控制台:
> my_app@ start /app
> node server.js
Migrations: Up to date at version 003
Ghost is running in development...
Listening on 127.0.0.1:8080
Url configured as: http://localhost:8080
Ctrl+C to shut down
docker ps
输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4f4c7027f62f my_app:latest "/nodejs/bin/npm sta 23 hours ago Up About a minute 0.0.0.0:49165->8080/tcp pensive_lovelace
并boot2docker ip
输出:
The VM's Host only interface IP address is: 192.168.59.103
因此,我将浏览器指向:192.168.59.103:49165,但什么也没得到,Docker 日志中没有输出。就像我上面说的,在同样的环境中运行“Hello World”应用程序server.js
很好。
一切对我来说都是正确的。我看到的唯一奇怪的事情是 sqlite3 在以下npm install
期间失败docker build
:
[sqlite3] Command failed:
module.js:356
Module._extensions[extension](this, filename);
^
Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found
...
node-pre-gyp ERR! Testing pre-built binary failed, attempting to source compile
但源代码编译似乎成功了。
我希望我只是在这里做一些愚蠢的事情。