连接到mariadb的ghost会出现连接错误

时间:2018-02-25 08:47:48

标签: docker docker-compose mariadb ghost

我正在尝试将我的ghost数据保存在mariadb docker容器而不是内置数据库中的ghost。它在docker-compose上,我有:

搬运工-compose.yml

version: '3'

services:
  mariadb-container:
    image: mymariadb:latest
    restart: always
    ports:
      - 3306:3306
    # volumes:
    #   - ~/blog/mariadb:/var/lib/mysql

  ghost-container:
    image: myghost:latest
    restart: always
    ports:
      - 2368:2368
    depends_on:
      - mariadb-container
    # volumes:
    #   - ~/blog/content:/var/lib/ghost/content
    links:
      - mariadb-container

myghost / Dockerfile

FROM ghost:latest

EXPOSE 2368

ADD ./config.production.json /var/lib/ghost

myghost / config.production.json

{
    "url": "http://localhost:2368/",
    "server": {
      "port": 2368,
      "host": "0.0.0.0"
    },
    "database": {
        "client": "mysql",
        "connection": {
          "host": "localhost",
          "port": 3306,
          "user": "root",
          "password": "pass123456",
          "database": "ghostblog",
          "socketPath": "/var/run/mysqld/mysqld.sock"
        }
    },
    "mail": {
      "transport": "Direct"
    },
    "logging": {
      "transports": [
        "file",
        "stdout"
      ]
    },
    "process": "systemd",
    "paths": {
      "contentPath": "/var/lib/ghost/content"
    }

mymariadb / Dockerfile

FROM mariadb:latest

EXPOSE 3306

ENV MYSQL_ROOT_PASSWORD=pass123436
ENV MYSQL_DATABASE=ghostblog

错误::

但是我得到了:

ghost-container_1    | NAME: RollbackError
ghost-container_1    | CODE: ENOENT
ghost-container_1    | MESSAGE: connect ENOENT /var/run/mysqld/mysqld.sock
ghost-container_1    |
ghost-container_1    | level:normal
ghost-container_1    |
ghost-container_1    | OuterError: The server has encountered an error.
ghost-container_1    | RollbackError: connect ENOENT /var/run/mysqld/mysqld.sock

现在,我在config.production.json中包含了socketPath,因为没有它我得到了:

ghost-container_1    | NAME: RollbackError
ghost-container_1    | CODE: ECONNREFUSED
ghost-container_1    | MESSAGE: connect ECONNREFUSED 127.0.0.1:3306
ghost-container_1    |
ghost-container_1    | level:normal
ghost-container_1    |
ghost-container_1    | OuterError: The server has encountered an error.
ghost-container_1    | RollbackError: connect ECONNREFUSED 0.0.0.0:3306

我还确保了'绑定地址'在mariadb的配置中注释掉了,因为这是我在搜索错误时看到的第一件事,我也尝试在config.production.json和docker中用0.0.0.0或127.0.0.1替换localhost -compose.yml但错误没有变化。

另外,我经常做docker build --no-cache和docker-compose up --force-recreate以确保我所做的更改实际上正在加载。

有谁知道我做错了什么?

2 个答案:

答案 0 :(得分:0)

您的数据库和幽灵位于不同的容器中,您可以创建网络以允许它们通过网络相互通信。

<强>搬运工-compose.yml

version: '3'

services:
  mariadb:
    image: mymariadb:latest
    restart: always
    ports:
      - 3306:3306
    # volumes:
    #   - ~/blog/mariadb:/var/lib/mysql
    networks:
        - web-network

  ghost:
    image: myghost:latest
    restart: always
    ports:
      - 2368:2368
    depends_on:
      - mariadb-container
    # volumes:
    #   - ~/blog/content:/var/lib/ghost/content
    networks:
        - web-network

networks:
  web-network:
    driver: bridge

ghost config (仅限数据库部分)

"database": {
    "client": "mysql",
    "connection": {
      "host": "mariadb", // your database container's name in network
      "port": 3306,
      "user": "root",
      "password": "pass123456",
      "database": "ghostblog"
    }
},

答案 1 :(得分:0)

如果您正在使用nginx,letsencrypt,ghost和mariadb查看正在运行的docker环境,它可能会对您有所帮助:

来源

重要提示

现在,当你试图从幽灵中拉出来时,有一个泊坞虫:最新。 如果你是从幽灵中拉出来的:1.22.1 - 它有效。 (您必须在docker-compose.yml中更改它)