利用docker 创建mysql_1.使用Ghost-Docker 构建博客并配置Mysql数据库

本文介绍了如何利用Docker安装Ghost博客,并将默认的sqlite3数据库切换为MySQL。首先,通过yum安装Docker并启动服务。接着,拉取Ghost镜像并启动容器,映射至80端口。然后,进入容器安装Vim编辑器,修改配置文件以使用生产模式和MySQL数据库。最后,更新MySQL连接信息,并重启Ghost容器以应用更改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

75ba19930c51

1. 安装Docker

使用yum下载

yum -y install docker

启动Docker后台服务

service docker start

2. 使用Docker安装Ghost镜像

安装镜像

docker pull ghost

查看镜像

docker images

75ba19930c51

REPOSITORY:仓库地址

TAG:版本

IMAGE ID:镜像编号

启动镜像,映射致80端口

docker run -d --name ${names} -p 80:2368 -d ${image}

#${names}: 容器启动后自定义名称

#${image}: 启动镜像ID-对应下载的镜像

查看运行的容器

docker ps -a

75ba19930c51

COMMAND:指令,entrypoint使容器表现类似可执行程序,可以传递参数

PORTS:本机端口到docker容器映射关系

访问本机IP可以看到画面,Ghost部署完成。

75ba19930c51

3. 使用Mysql数据库

Ghost默认使用sqlite3微型数据库,当数据增长会比较卡,推荐切换成Mysql

进入Docker-Ghost容器

docker exec -it ${container_id} /bin/bash

安装Vim编辑器

#更新apt-get

apt-get update

#安装vim

apt-get install vim

进入容器后默认在Ghost目录:/var/lib/ghost

进入当前部署目录/var/lib/ghost/current/core

Docker默认使用的dev开发模式,修改为prod生产模式

cd /var/lib/ghost/current/core

vim index.js

// ## Server Loader

// Passes options through the boot process to get a server instance back

var server = require('./server');

// 将下面的`development`修改为`production`

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

function makeGhost(options) {

options = options || {};

return server(options);

}

module.exports = makeGhost;

使用:wq保存退出

进入DB配置文件目录: /var/lib/ghost/current/core/server/config/env

修改config.production.json

{

"database": {

"client": "mysql",

"connection": {

"host" : "172.17.0.1",

"user" : "",

"password" : "",

"database" : ""

}

},

"paths": {

"contentPath": "content/"

},

"logging": {

"level": "info",

"rotation": {

"enabled": true

},

"transports": ["file", "stdout"]

}

}

修改Mysql连接,如果主容器通信,只需要查看容器IP

docker inspect ${container_id}

"Networks": {

"bridge": {

"IPAMConfig": null,

"Links": null,

"Aliases": null,

"NetworkID": "",

"EndpointID": "",

"Gateway": "172.17.0.1",

"IPAddress": "172.17.0.3",

"IPPrefixLen": 16,

"IPv6Gateway": "",

"GlobalIPv6Address": "",

"GlobalIPv6PrefixLen": 0,

"MacAddress": ""

}

}

修改完毕使用:wq退出

Ctrl + D退出容器

停掉Ghost,重新启动

docker stop ${container_id}

docker start ${container_id}

Ghost会自动在Mysql中创建所需表。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值