使用Docker搭建wordpress个人博客网站附遇到的问题解决

1. Docker安装

sudo apt-get update  #更新下载
sudo apt-get install -y docker.io   #下载docker
systemctl start docker    #启动docker
systemctl status docker
systemctl stop docker.socket
systemctl enable docker   #设置docker开机自启
docker version       #查看docker版本

2. docker-compose安装

前提:
有些版本的系统默认是python2,但是也有python3,此时建议将python3作为默认的python

# 先删除默认的Python软链接:
sudo rm -rf /usr/bin/python

# 创建一个新的软链接指向需要的Python版本:
sudo ln -s /usr/bin/python3 /usr/bin/python

# 如果想还原回原python2.7,只需
sudo rm -rf /usr/bin/python
sudo ln -s /usr/bin/ptyhon2.7 /usr/bin/python

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose
docker-compose -v  # 查看docker-compose版本

安装docker-compose可能会出现失败的情况, 这时候需要更新以下pip3

pip3 install --upgrade pip   # 更新pip3

3. 一键安装

在某个位置新建一个文件夹my_wordpress并进入文件夹新建名为 docker-compose.yml 的文件

mkdir my_wordpress
cd my_wordpress/
touch docker-compose.yml

将如下内容粘贴到docker-compose.yml文件中

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

在当前目录下使用一行命令启动docker容器(会自动找到docker-compose.yml文件):

docker-compose up -d

4. 问题解决

上一步大概率会出现错误

问题一:

/usr/local/lib/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.hazmat.backends import default_backend

python3.6版本和Cryptography库的版本不兼容:

pip show Cryptography # 先查看已经安装的Cryptography版本
pip uninstall  cryptography # 卸载 cryptography 
pip install  cryptography==  # 查看cryptography 有哪些版本
pip install  cryptography==3.4.8  # 安装一个较低的版本

问题二:

You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

docker-compose.yml中指定的version和docker engine版本不兼容‘

查看docker版本docker --version修改对照下表 docker-compose.yml 文件中的version

5. 访问博客

看到刚刚启动了两个容器

访问:http://ip地址:8000/

看到如下页面就表示安装成功了

再次访问主页:http://ip地址:8000/

后续可以更换主题

posted @ 2023-04-14 11:20  junlin623  阅读(439)  评论(0编辑  收藏  举报