在docker中安装WordPress

如下操作在centos7中完成

一、Docker CE安装

  • 1.检查是否安装过旧的版本

如果系统安装旧版本Docker需要先卸载,命令如下:

# sudo yum remove docker \
> docker-common \
> docker-selinux \
> docker-engine
  • 2.本文基于yum方式安装,需要安装以下的依赖包:yum-utils 、device-mapper-persistent-data、lvm2命令如下:
# sudo yum install -y yum-utils \
> device-mapper-persistent-data \
> lvm2
  • 3.基于yum命令配置Docker CE仓库,命令如下:
# sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
  • 4.安装docker CE 命令如下:
# sudo yum install docker-ce

结果如下:

Installed:
  docker-ce.x86_64 0:18.03.0.ce-1.el7.centos                                                                                         

Dependency Installed:
  container-selinux.noarch 2:2.42-1.gitad8f0f7.el7       libtool-ltdl.x86_64 0:2.4.2-22.el7_3       pigz.x86_64 0:2.3.4-1.el7      

Complete!
  • 5.启动docker
# sudo systemctl start docker
  • 6.运行docker run hello-world
# sudo docker run hello-world

结果查看:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete 
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
  • 7.查看docker版本
# docker version
Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:09:15 2018
 OS/Arch:       linux/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:      18.03.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   0520e24
  Built:        Wed Mar 21 23:13:03 2018
  OS/Arch:      linux/amd64
  Experimental: false

二、安装docker-compose

# curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

结果如下:

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    571      0 --:--:--  0:00:01 --:--:--   571
100 10.3M  100 10.3M    0     0   511k      0  0:00:20  0:00:20 --:--:-- 1703k
  • 3.对二进制文件应用可执行权限
# chmod +x /usr/local/bin/docker-compose
  • 4.查看docker-compose版本:
# docker-compose version
docker-compose version 1.21.0, build 5920eb0
docker-py version: 3.2.1
CPython version: 3.6.5
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

三、使用docker-compose安装wordpress

  • 1.创建一个空的项目目录。
# mkdir Wordpresss
  • 2.切换到目录
cd Wordpresss/
  • 3.创建一个docker-compose.yml启动您的WordPress博客的文件, 并创建一个独立MySQL实例,并使用卷挂接来实现数据持久性:
# vi 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:
  • 4.建立项目
# docker-compose up
  • 5.浏览器输入地址+端口(若无法打开,可检查一下8000端口是否开启),进入WordPress初始化页面

安装之后进入WordPress主页:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值