[Docker] Deploy your own website

Original link: https://grimoire.cn/intro/site-with-blog.html

install docker

First we update the server software

 sudo apt-get update sudo apt-get upgrade

Then we install docker

 curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

After waiting for a while, after the installation is complete, let’s check the version number:

 [email protected]:~$ docker -v Docker version 20.10.18, build b40c2f6

Next, let’s change the source for docker

 sudo vim /etc/docker/daemon.json

Write this data in:

 { "registry-mirrors": [ "http://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com", "http://registry.docker-cn.com" ] }

Then restart docker

 sudo systemctl restart docker

Let’s try to run docker:

 [email protected]:~$ docker ps -a Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied

! ! Note: If the above error occurs, it means that docker needs to run under root privileges. If you don’t want to switch to the root user, you can try this: ! !

 sudo gpasswd -a $USER docker newgrp docker # 将当前用户加入docker 群组,并且切换到docker 群组中# 如果不行就在root 用户下直接开干吧,勇敢点!


Create a folder to store the data of the docker container

 sudo mkdir -p ~/docker # 这个代表在当前用户文件夹下创建一个名为docker 的文件夹# 我只是做一个样例,实际安装的时候请自行选择路径

Then we create a network:

 docker network create example_net

Let’s check if the creation is successful

 docker network ls NETWORK ID NAME DRIVER SCOPE 3447a91e9bd6 bridge bridge local 6e5b947ca9d2 example_net bridge local da90d970b57e host host local 9fc38aa66b38 none null local

We may need several domain names next, because dns resolution takes time, we can go to the dns service provider to resolve in advance

Install a reverse proxy server

Here we choose the simpler caddy to replace nginx. Before installation, we first try to create a Caddyfile , which will be used as caddy’s configuration file:

 mkdir -p ~/docker/caddy sudo vim ~/docker/caddy/Caddyfile

We put these in:

 :80 { root * /usr/share/caddy file_server }

Ok, let’s install caddy

 docker run -itd \ -p 80:80 \ -p 443:443 \ -p 443:443/udp \ -v ~/docker/caddy/config:/config \ -v ~/docker/caddy/data:/data \ -v ~/docker/caddy/site:/srv \ -v ~/docker/caddy/Caddyfile:/etc/caddy/Caddyfile \ --net example_net \ --name caddy \ caddy:alpine # 因为caddy 是反向代理服务器,所以需要将自己的80, 443, 以及443/udp 端口暴露出去, # 暴露443/udp 是因为caddy 可以通过配置启用实验性的http3/quic 协议,这个协议需要使用443/udp

Check if it started correctly

 [email protected]:~/docker/caddy$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f65bba2ca1fe caddy:alpine "caddy run --config …" 8 seconds ago Up 6 seconds>80/tcp, :::80->80/tcp,>443/tcp, :::443->443/tcp,>443/udp, :::443->443/udp, 2019/tcp caddy

Then we visit http://your-ip :


If this screen appears, then we’re done!

More: caddy official website

install filebrowser

filebrower is a concise file management system

As usual, because we want to mount the file, we still manually create this file first

 sudo mkdir -p ~/docker/caddy/site/filebrowser sudo touch ~/docker/caddy/site/filebrowser/filebrowser.db # 数据库空着就行sudo vim ~/docker/caddy/site/filebrowser/settings.json # 我们写一下配置文件

Write the following to ~/docker/caddy/site/filebrowser/settings.json :

 { "port": 80, "baseURL": "", "address": "", "log": "stdout", "database": "/database/filebrowser.db", "root": "/srv" }

We add permissions for filebrowser.db and settings.json

 cd ~/docker/caddy/site/filebrowser sudo chmod 666 filebrowser.db settings.json # 为这两个文件增加读写权限

Then we install filebrowser

 docker run -itd \ -v ~/docker/caddy:/srv \ -v ~/docker/caddy/site/filebrowser/filebrowser.db:/database/filebrowser.db \ -v ~/docker/caddy/site/filebrowser/settings.json:/config/settings.json \ -e PUID=$(id -u) \ -e PGID=$(id -g) \ --net example_net \ --name filebrowser \ filebrowser/filebrowser:s6

Check if the installation was successful

 [email protected]:~/docker/caddy/site/filebrowser$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0201afc646e3 filebrowser/filebrowser:s6 "/init" About a minute ago Up About a minute (healthy) 80/tcp filebrowser f65bba2ca1fe caddy:alpine "caddy run --config …" 20 minutes ago Up 20 minutes>80/tcp, :::80->80/tcp,>443/tcp, :::443->443/tcp,>443/udp, :::443->443/udp, 2019/tcp caddy

If the status of the filebrowser is not healthy, try this:

 docker stop filebrowser # 暂停filebrowser docker start -i filebrowser # 在前台启动filebrowser,这将会打印出日志# 然后就可以根据日志来判断出当前的状态了# 如果出现permission xxx,应该是权限相关的问题

Let’s modify the Caddyfile and let caddy reverse proxy under the filebrowser

 filebrowser.your-domain.com { reverse_proxy filebrowser:80 }

Restart caddy:

 docker restart caddy

Remember to go to the DNS service provider to resolve filebrowser.your-domain.com in advance

It is also possible to replace this domain name with another one, but remember to parse it, because the blogger installed it on this machine, so I just use other ports, but the principle is the same

There is one thing to pay attention to. It is best to configure the caddyfile after the dns resolution takes effect, because caddy will try to apply for the ssl certificate with this domain name. If the domain name resolution does not take effect, the ssl certificate application may fail, resulting in Inaccessible!

Visit https://filebrowser.your-domain.com :


The initial account password should be:

 username: admin password: admin

After logging in, you should see several folders like this:


Then our file management program is done!

Install the database

We choose open source mariadb for database: this database is compatible with mysql

 docker run -itd \ -v ~/docker/mariadb:/var/lib/mysql \ -e MARIADB_ROOT_PASSWORD=my_password \ --net example_net \ --name mariadb \ mariadb

There is nothing to say about this, just remember to replace the password inside with your own.

We enter mariadb, create a database typecho in it, and store its own data for typecho

When running these commands, you can also use database management tools like navicat, but as a hard-core tutorial, let’s start the command line directly here!

 docker exec -it mariadb /bin/bash # 进入mariadb 容器内mysql -p # 使用密码连接数据库

Let’s create a new database:

 MariaDB [(none)]> create database typecho;

Check if the creation is successful:

 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | typecho | +--------------------+ 5 rows in set (0.001 sec)

Database installed successfully!

install typecho

Just create

 docker run -itd \ -e TYPECHO_DB_ADAPTER=Pdo_Mysql \ -e TYPECHO_DB_HOST=mariadb \ -e TYPECHO_DB_PORT=3306 \ -e TYPECHO_DB_USER=root \ -e TYPECHO_DB_PASSWORD=my_password \ -e TYPECHO_DB_DATABASE=typecho \ -e TYPECHO_SITE_URL=your-domain.cn \ --name typecho \ --net example_net \ -v ~/docker/caddy/site/your-domain.cn:/app/usr \ joyqi/typecho:nightly-php8.0-apache

Modify the Caddyfile and add typecho related information

 filebrowser.your-domain.com { reverse_proxy filebrowser:80 } your-domain.com { reverse_proxy typecho:80 }

Restart the Caddy container

 docker restart caddy

Check if the next page is normal


These places need to be modified and changed to something like the picture.


Just install it all the way and you’re done


If you want to modify any file under the website, you can modify it directly through https://filebrowser.your-domain.com , which is very convenient


1. Why not use docker-compose?

emm, maybe I think my server might deploy more extended content?

2. Why can’t I run it?

Ah, I really don’t know. The instructions given in this article are all tested by the blogger in the virtual machine of the ubuntu22.04-server version. There should be no problem in theory.

3. Why do you choose this technology?

Well, personal blog, don’t care about performance, just run it, it’s simple

4. Other instructions

 docker ps -a # 所有的容器
docker stop container-name # 暂停一个容器docker start container-name # 启动一个容器docker start -i container-name # 在前台启动一个容器docker rm container-name # 删除一个容器docker rmi contaienr-name # 删除一个镜像docker restart container-name # 重启一个容器
docker exec -it docker-name /bin/bash # 进入一个容器docker exec -it docker-name /bin/sh # 进入一个容器(一般是alpine 镜像)
 docker network create network_name # 创建一个网络docker network connect container-name # 将容器加入到一个网络中docker network disconnect container-name # 将容器从一个网络中删除
docker update --restart=always container-name # 设置容器重启
docker inspect container-name # 查看container 详细信息

5. Reference Links

joyqi/typecho – Docker Image | Docker Hub

mariadb – Official Image | Docker Hub

caddy – Official Image | Docker Hub

filebrowser/filebrowser – Docker Image | Docker Hub

Installation – File Browser

Welcome — Caddy Documentation (caddyserver.com)

Docker Introduction and Installation – Docker Quick Start – Easy Documentation (easydoc.net)

This article is reproduced from: https://grimoire.cn/intro/site-with-blog.html
This site is for inclusion only, and the copyright belongs to the original author.