当前位置: 首页 > news >正文

使用Compose编排工具搭建Ghost博客系统

序:需要提前自备一台部署好docker环境的虚拟机,了解并熟练compose编排工具

在Centos7中,在线/离线安装Docker:https://blog.csdn.net/2301_82085712/article/details/147140694

Docker编排工具---Compose的概述及使用:https://blog.csdn.net/2301_82085712/article/details/147776436


目录

实验目的

实验步骤

1、拉取在线centos 7的yum源和epel扩展源

2、安装compose工具

3、获取所需的镜像(ghost、mysql、nginx)

4、创建ghost目录,在ghost目录中创建三个子目录(data、ghost、nginx)

5、切换到ghost目录的ghost子目录,编写Dockerfile文件

6、创建config.js文件,用于ghost的配置

7、切换到ghost目录的nginx的子目录中,编写Dockerfile文件

8、配置nginx的配置文件nginx.conf

9、返回到ghost目录,编写docker-compose.yml文件

10、执行脚本文件,完成服务的安装与部署,并查看创建的服务

11、测试,访问Ghost博客


实验目的

        利用Compose编排服务搭建博客系统,用户可以通过nginx来访问博客系统。

实验步骤

1、拉取在线centos 7的yum源和epel扩展源

## 拉取在线centos7的yum源
[root@docker ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2025-05-06 22:33:34--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 183.131.64.61, 183.131.64.19.215
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|183.131.64.61|:443... con
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’100%[=================================================>] 2,523       --.-K/s2025-05-06 22:33:34 (234 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]## 拉取在线epel扩展源
[root@docker ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2025-05-06 22:33:39--  https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 183.131.64.66, 219.151.19.20.236
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|183.131.64.66|:443... con
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’100%[=================================================>] 664         --.-K/s2025-05-06 22:33:39 (53.2 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]

2、安装compose工具

[root@docker ~]# yum -y install docker-compose
[root@docker ~]# docker-compose --version
docker-compose version 1.18.0, build 8dd22a9

3、获取所需的镜像(ghost、mysql、nginx)

[root@docker ~]# docker pull ghost:1-alpine
[root@docker ~]# docker pull mysql:5.7.15
[root@docker ~]# docker pull nginx:latest
[root@docker ~]# docker images
REPOSITORY   TAG        IMAGE ID       CREATED       SIZE
nginx        latest     a830707172e8   2 weeks ago   192MB
ghost        1-alpine   efcd4044e3a0   5 years ago   268MB
mysql        5.7.15     18f13d72f7f0   8 years ago   383MB

4、创建ghost目录,在ghost目录中创建三个子目录(data、ghost、nginx)

[root@docker ~]# mkdir /ghost
[root@docker  ~]# cd /ghost/
[root@docker ghost]# mkdir {data,ghost,nginx}
[root@docker ghost]# ls
data ghost nginx

5、切换到ghost目录的ghost子目录,编写Dockerfile文件

[root@docker ghost]# cd ghost/
[root@docker ghost]# vi Dockerfile
[root@docker ghost]# cat Dockerfile
FROM ghost:1-alpine
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
#CMD ["npm","start","--production"]

6、创建config.js文件,用于ghost的配置

[root@docker ghost]# vi config.js
[root@docker ghost]# cat config.js
var path = require('path'),config;config = {production: {url: 'http://my-ghost-blog.com',mail: {},database: {client: 'mysql',connection: {host: 'db',user: 'ghost',password: '123456',database: ''ghost,port: '3306',charset: ''utf-8,},debug: false},paths: {contentPath: path.jion(process.env.GHOST_CONTENT, '/')},server: {host: '0.0.0.0',port: '2368'},}
}
// Export config
module.exports = config;

7、切换到ghost目录的nginx的子目录中,编写Dockerfile文件

[root@docker ghost]# cd ../nginx
[root@docker nginx]# vi Dockerfile
[root@docker nginx]# cat Dockerfile
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

8、配置nginx的配置文件nginx.conf

[root@docker nginx]# vi nginx.conf
[root@docker nginx]# cat nginx.conf
work_processes 4;
events {worker_connections 1024;}
http {server{listen 80;location / {proxy_pass http://ghost-app:2368;}}
}

9、返回到ghost目录,编写docker-compose.yml文件

[root@docker nginx]# cd ..
[root@docker ghost]# vi docker-compose.yml
[root@docker ghost]# cat docker-compose.yml
version: "3"
networks:blog:
services:ghost-app:build: ghostrestart: alwaysnetworks:- blogdepends_on:- dbports:- "2368:2368"nginx:build: nginxrestart: alwaysnetworks:- blogdepends_on:- ghost-appports:- "80:80"db:image: "mysql:5.7.15"networks:- blogenvironment:MYSQL_ROOT_PASSWORD: mysqlrootMYSQL_USER: ghostMYSQL_PASSWORD: 123456volumes:- $PWD/data:/var/lib/mysqlports:- "3306:3306"

## 检测docker-compose.yml编排文件

[root@docker ghost]# docker-compose config

10、执行脚本文件,完成服务的安装与部署,并查看创建的服务

[root@tangjing ghost]# docker-compose up -d
Creating network "ghost_blog" with the default driver
Building ghost-app
Step 1/3 : FROM ghost:1-alpine---> efcd4044e3a0
Step 2/3 : COPY ./config.js /var/lib/ghost/config.js---> b2d75401677c
Step 3/3 : EXPOSE 2368---> Running in 6122339f4b69---> Removed intermediate container 6122339f4b69---> 64d47c621ef8
Successfully built 64d47c621ef8
Successfully tagged ghost_ghost-app:latest
WARNING: Image for service ghost-app was built because it did not already exist this image you must use `docker-compose build` or `docker-compose up --build`.
Building nginx
Step 1/3 : FROM nginx---> a830707172e8
Step 2/3 : COPY nginx.conf /etc/nginx/nginx.conf---> 481129bd9419
Step 3/3 : EXPOSE 80---> Running in 5aa7ec064fe2---> Removed intermediate container 5aa7ec064fe2---> d13bf46137cd
Successfully built d13bf46137cd
Successfully tagged ghost_nginx:latest
Creating ghost_db_1        ... done
s image you must use `docker-compose build` or `docker-compose up --build`.
Creating ghost_ghost-app_1 ... done
Creating ghost_ghost-app_1 ...
Creating ghost_nginx_1     ... done
[root@docker ghost]# docker-compose psName                     Command                 State                       Ports                  
----------------------------------------------------------------------------------------------------------
ghost_db_1          docker-entrypoint.sh mysqld      Up           0.0.0.0:3306->3306/tcp,:::3306->3306/tcp
ghost_ghost-app_1   docker-entrypoint.sh node  ...   Up           0.0.0.0:2368->2368/tcp,:::2368->2368/tcp
ghost_nginx_1       /docker-entrypoint.sh ngin ...   Up           0.0.0.0:80->80/tcp,:::80->80/tcp

## 三个服务的状态需是“Up”,则表示服务创建并启动成功!!!

11、测试,访问Ghost博客

( http://IP:80,http://IP:2368 )

相关文章:

  • 《易语言学习大全》
  • maven如何搭建自己的私服(LINUX版)?
  • ubuntu 22.04 换源
  • Java内存分配
  • 天选5Pro(锐龙版)设备声音、显卡消失等问题完整解决记录
  • C++使用PoDoFo库处理PDF文件
  • WPF实时调试的一种实现方法
  • 推测式思维树:让大模型快速完成复杂推理
  • 探索网络设备安全:Shodan 的原理与合法应用
  • 接口自动化测试框架详解(pytest+allure+aiohttp+ 用例自动生成)
  • C++GO语言微服务基础技术②
  • vite 代理 websocket
  • Golang中集合相关的库
  • 系统思考助力富维东阳
  • pycharm无法导入相对路径下其它文件
  • 书法机构用的教务管理系统
  • 从装饰器出发,优雅处理 UI 自动化中的异常
  • Ubuntu每次开机IP都是127.0.0.1
  • JS 问号(?)运算符避免中间报错
  • 【Python从入门到精通】--‘@‘符号的作用
  • 保证断电、碰撞等事故中车门系统能够开启!隐藏式门把手将迎来强制性国家标准
  • 首批证券公司科创债来了!拟发行规模超160亿元
  • 奥园集团将召开债券持有人会议,拟调整“H20奥园2”本息兑付方案
  • 一季度全国消协组织为消费者挽回经济损失23723万元
  • 江淮、极氪、奇瑞,排着队造“劳斯莱斯”
  • 农行原首席专家兼浙江省分行原行长冯建龙主动投案被查