ghost的docker镜像映射端口无效

浏览:35日期:2023-03-07

问题描述

系统环境ubuntu 14.04 64bitdocker 1.6.0ghost镜像操作下载镜像ghost&&自己制作ghost镜像docker run -it -p 127.0.0.1::2368 ghost bashnpm start启动ghost成功另起一个shelldocker ps -a

adolph@geek:~$ docker ps -aCONTAINER IDIMAGE COMMANDCREATED STATUS PORTS NAMES84802ccaa8f7ghost:latest'/entrypoint.sh bash 32 seconds ago Up 31 seconds 127.0.0.1:32769->2368/tcp kickass_belladolph@geek:~$ 问题描述

在浏览器输入localhost:32769后无法连接到资源

想知道到底是哪里除了问题?

ghost的Dockerfile

shell#build ghost imageFROM adolphlwq/ubuntu:14.04_64_base_imageMAINTAINER adolphlwq <nalan3015@126.com>ENV REFRESHED_AT 2015-6-9RUN apt-get update && apt-get -yqq upgrade#install nodeRUN apt-get install -yqq nodejs npm wget unzip RUN ln -s /usr/bin/nodejs /usr/bin/node#install ghost-zhRUN cd /opt/ && wget http://dl.ghostchina.com/Ghost-0.6.3-zh-full.zip && unzip -uo Ghost-0.6.3-zh-full.zip -d ghost && rm Ghost-0.6.3-zh-full.zip#initial ghostRUN cd /opt/ghost && npm install --production#workdirWORKDIR /opt/ghost/#expose port 2368EXPOSE 2368CMD npm start

然后我又看了Daocloud上ghost的镜像Dockerfile,核心的地方是类似的,不知道我的问题出在哪,端口映射一直失败daocloud上ghost的Dockerfile

问题解答

回答1:

ghost文件目录下有个config.example.js文件用来配置相关参数:

config = { // ### Production // When running Ghost in the wild, use the production environment. // Configure your URL and mail settings here production: {......},server: { host: ’0.0.0.0’, port: ’2368’} },

问题的核心在server项的配置。默认是localhost好像,一般主机默认的localhost是和127.0.0.1对应的(你也可以在/etc/hosts修改)。localhost是一个伪造的ip,只能本机访问。0.0.0.0类似通配符*的作用,能匹配任意ip。详情见这个回答。

所以你应该修改config.example.js的配置项,把server绑定的地址改为0.0.0.0就可以了。

最后,我也做了一个ghost的docker image,而且也用nginx配置的代理。使用了Let’s Encrypt加密https,你可以参考下:

Docker image:qBlog

my blog

回答2:

竟然没有人回答,我也是碰到相同的问题,自己做的nginx镜像,Dockerfile中也有EXPOSE一个端口,run镜像时,即使没有使用-p参数也一样可以通过宿主机的IP访问到镜像的服务,而指定-p参数打开端口映射时无一生效。mark一下,我先去找找答案

相关文章: