Centos7下實現docker + wordpress 安裝

1、Docker CE 安裝

檢查是否安裝過舊的版本

若是系統安裝舊版本Docker須要先卸載,命令以下:mysql

[root@localhost Wordpresss]sudo yum remove docker \
> docker-common \
> docker-selinux \
> docker-engine

安裝如下的依賴包

[root@localhost Wordpresss]sudo yum install -y yum-utils \
> device-mapper-persistent-data \
> lvm2

配置Docker CE倉庫

[root@localhost Wordpresss]sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

安裝docker CE

[root@localhost Wordpresss]sudo  yum install docker-ce

啓動docker

[root@localhost Wordpresss]sudo  systemctl start docker

查看docker版本

[root@localhost Wordpresss]docker version

2、安裝docker-compose

安裝最新版本的docker-compose

[root@localhost Wordpresss]curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

對二進制文件應用可執行權限

[root@localhost Wordpresss]chmod +x /usr/local/bin/docker-compose

查看docker-compose版本

[root@localhost Wordpresss]docker-compose version

3、使用docker-compose安裝wordpress

建立一個空的項目目錄

[root@localhost Wordpresss]mkdir /usr/local/wordpress

切換到目錄

[root@localhost Wordpresss]cd /usr/local/wordpress

建立docker-compose.yml啓動WordPress博客的文件, 並建立一個獨立MySQL實例,並使用卷掛接來實現數據持久性

vi docker-compose.ymllinux

# 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
volumes:
    db_data:

創建項目

[root@localhost Wordpresss]docker-compose up

瀏覽器輸入地址+端口(若沒法打開,可檢查一下8000端口是否開啓),進入WordPress初始化頁面

相關文章
相關標籤/搜索