ghost的docker镜像映射端口无效
天蓬老师
天蓬老师 2017-04-22 08:55:40
0
2
792

系统环境

  • ubuntu 14.04 64bit
  • docker 1.6.0
  • ghost镜像

操作

  1. 下载镜像ghost&&自己制作ghost镜像
  2. docker run -it -p 127.0.0.1::2368 ghost bash
  3. npm start启动ghost成功
  4. 另起一个shelldocker ps -a
adolph@geek:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                       NAMES
84802ccaa8f7        ghost:latest        "/entrypoint.sh bash   32 seconds ago      Up 31 seconds       127.0.0.1:32769->2368/tcp   kickass_bell        
adolph@geek:~$ 

问题描述

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

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

ghost的Dockerfile

shell#build ghost image
FROM adolphlwq/ubuntu:14.04_64_base_image
MAINTAINER adolphlwq <nalan3015@126.com>
ENV REFRESHED_AT 2015-6-9

RUN apt-get update && apt-get -yqq upgrade

#install node
RUN apt-get install -yqq nodejs npm wget unzip 
RUN ln -s /usr/bin/nodejs /usr/bin/node

#install ghost-zh
RUN 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 ghost
RUN cd /opt/ghost && npm install --production

#workdir
WORKDIR /opt/ghost/

#expose port 2368
EXPOSE 2368

CMD npm start

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回覆(2)
伊谢尔伦

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

迷茫

竟然沒有人回答,我也是碰到相同的問題,自己做的nginx鏡像,Dockerfile中也有EXPOSE一個端口,run鏡像時,即使沒有使用-p參數也一樣可以通過宿主機的IP訪問到鏡像的服務,而指定-p參數開啟連接埠對映時無一生效。 mark一下,我先去找答案

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!