preface

The original

Recently, I have studied the docker container of fire in depth. I want to do a small project to practice my skills. I just want to upgrade my previous blog to be more geek. Therefore, it is necessary to build ghost blog tutorial from scratch.

Why docker

Docker is really an amazing piece of technology. In the past, ghost blog or other blog sites, there are extremely complex steps and many unexpected obstacles, simply speaking, is a steep learning curve, and the use of docker container technology, the image of others to transform, second build personal blog

Why the ghost

Because geek, 🙂

The overall architecture

A total of two containers, one is the blog service ghost container, the other is the mysql database image

steps

Create a custom network

docker network create ghost_blog_dev

Docker custom bridge network will have DNS function, ghost can connect to mysql container by container name instead of IP address.

Create the mysql data store directory

After the mysql container is destroyed, the data generated is also destroyed. So we need to store the data volume on the host, so create the data directory first.

mkdir -p /data/blog/
Copy the code

Start mysql container

docker run -d --name mysql -v /data/blog/:/var/lib/mysql --network ghost_blog_dev -e MYSQL_ROOT_PASSWORD=123456 mysql
Copy the code

-v specifies the directory of the data volume, –network specifies the network to connect to, and –name specifies the name of the mysql container.

docker logs mysql

Connect to mysql

The IP address of the mysql container is displayed

docker network inspect ghost_blog_dev
Copy the code

Connect to mysql on host with password 123456

Alter user root login auth to native, because ghost container does not support mysql 8.0 login authentication.

ALTER USER 'root'@The '%' IDENTIFIED WITH mysql_native_password BY '123456';
Copy the code

Create the GHOST database (table names are automatically created by the Ghost container)

create database ghost;
Copy the code

Building ghost Images

Pull the written image from my Github and build it as ghost:dev

docker build -t ghost:dev https://github.com/jiujiujiujiujiuaia/ghost_Dockerfile.git
Copy the code

Start Ghost

–name specifies the name of the container, –network specifies the network to connect to, — URL specifies the connection domain name of ghost website (there is no specified IP address of the domain name), -p specifies the port mapping relationship between the host and the container

docker run -d --name blog  --network ghost_blog_dev -eUrl = http://118.24.145.98 - p ghost: 80-2368 devCopy the code

Docker logs show that the container has been successfully started and the required tables have been created in our Ghost database

At the same time, in the data directory of the host machine, you can also see the data generated by the container persisted to the host machine.

Visit blogs!

With the above steps, the blog setup is complete! No need to understand complex software installation, software tool installation, various configurations, everything is pull image, boot container, bingo! Done!

Visit blogs!

About the configuration of the blog, you can enter the background management system through THE URL +/ghost configuration, here is not to say.

conclusion

To be continued