ubuntu通过docker-compose更快的迁移我的博客
安装dcoker方式移步
安装docker-compose
wget https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64 mv docker-compose-linux-x86_64 /bin/docker-compose chmod +x /bin/docker-compose
创建docker-compose编排配置文件
mkdir -p /data/myBlogDocker vim /data//myBlogDocker/myDockerCompose
写入如下内容
version: "3" services: php74: container_name: php74 build: context: ./php volumes: - /data/wwwroot:/var/www/html depends_on: - mysql57 networks: - note_network mysql57: image: mysql:5.7 container_name: mysql57 environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=123456 networks: - note_network nginx: container_name: nginx build: context: ./nginx volumes: - /data/wwwroot:/var/www/html ports: - "80:80" depends_on: - php74 networks: - note_network networks: note_network: driver: bridge
创建php构建配置文件
mkdir /data/myBlogDocker/php vim /data/myBlogDocker/php/Dockerfile
写入如下内容
FROM php:7.4-fpm WORKDIR /var/www/html # 安装所需的PHP扩展 RUN docker-php-ext-install mysqli pdo pdo_mysql COPY . .
创建nginx构建配置文件
mkdir /data/myBlogDocker/nginx vim /data/myBlogDocker/nginx/Dockerfile
写入如下内容
FROM nginx:1.23 COPY ./nginx.conf /etc/nginx/conf.d/default.conf
创建nginx配置文件
vim /data/myBlogDocker/nginx/nginx.conf
写入如下内容
server { listen 80; server_name localhost; # 请根据实际情况写域名 location / { root /var/www/html; # 将Nginx的根目录设置为容器中的/var/www/html index index.php index.html; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass php74:9000; # 将PHP-FPM代理到php服务的9000端口 fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; include fastcgi_params; } }
编排容器
cd /data/myBlogDocker docker-compose -f myDockerCompose up -d --build
把我的博客放在宿主机的/data/wwwroot目录搞定