• 制作LAMP架构镜像并上线wordpress



    拉取centos7镜像
    docker pull centos:7
    创建一个centos初始化目录
    mkdir /centos
    切换到目录
    cd /centos

    并按照如下的dockerfile初始化镜像
    vim Dockerfile
    FROM centos:7
    ENV container docker
    RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i ==
    systemd-tmpfiles-setup.service ] || rm -f $i; done);
    rm -f /lib/systemd/system/multi-user.target.wants/*;
    rm -f /etc/systemd/system/*.wants/*;
    rm -f /lib/systemd/system/local-fs.target.wants/*;
    rm -f /lib/systemd/system/sockets.target.wants/*udev*;
    rm -f /lib/systemd/system/sockets.target.wants/*initctl*;
    rm -f /lib/systemd/system/basic.target.wants/*;
    rm -f /lib/systemd/system/anaconda.target.wants/*;
    VOLUME [ "/sys/fs/cgroup" ]
    CMD ["/usr/sbin/init"]


    生成创建出来的centos镜像
    docker build -t centos:v1

    创建一个基于lamp的目录
    mkdir centos_lamp

    切换到lamp目录
    cd centos_lamp/


    把local.repo文件发送到镜像中,因为镜像文件没有mariad数据库
    local.repo文件内容
    vim local.repo

    [local]
    name=local
    enabled=1
    gpgcheck=0
    baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/

    ~

    编写制作LAMP架构的dockerfile
    vim Dockerfile
    FROM centos:v1
    COPY local.repo /etc/yum.repos.d/
    COPY wordpress /var/www/html/
    RUN yum -y install httpd mariadb-server php php-mysql; yum clean all; systemctl restart mariadb httpd;systemctl enable mariadb httpd.service
    EXPOSE 80 3306
    CMD ["/usr/sbin/init"]
     

    把配置好的wordpress安装包复制到网站根目录下并解压
    ls /centos/centos_lamp/
    Dockerfile local.repo wordpress wordpress-3.3.1-zh_CN.zip


    生成创建出来的lamp镜像
    docker build -t centos_lamp:v1

    运行容器
    docker run -d -v /sys/fs/cgroup/:/sys/fs/cgroup/ -p 888:80 --privileged centos-lamp:v1
     
    –privileged 让容器能够获得更多特权,否则在容器内部不能使用systemctl,会报如下的错
    Failed to get D-Bus connection: Operation not permitted
     
    进入容器创建数据库
    docker exec -it f80ed6fb67b3 bash
    [root@f80ed6fb67b3 /]# ls /var/www/html/
    index.php wp-activate.php wp-config-sample.php wp-links-opml.php wp-register.php
    license.txt wp-admin wp-config.php wp-load.php wp-settings.php
    readme.html wp-app.php wp-content wp-login.php wp-signup.php
    wordpress wp-blog-header.php wp-cron.php wp-mail.php wp-trackback.php
    wordpress-3.3.1-zh_CN.zip wp-comments-post.php wp-includes wp-pass.php xmlrpc.php
    切换到目录里
    cd /var/www/html

    复制编辑文件
    cp wp-config-sample.php wp-config.php
    vim wp-config.php
    define('DB_NAME', 'zxw');

    /** MySQL 数据库用户名 */
    define('DB_USER', 'zxw');

    /** MySQL 数据库密码 */
    define('DB_PASSWORD', '123');

     

    [root@f80ed6fb67b3 /]# mysql
    Welcome to the MariaDB monitor. Commands end with ; or g.
    Your MariaDB connection id is 2
    Server version: 5.5.60-MariaDB MariaDB Server
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    MariaDB [(none)]> create database ken;
    Query OK, 1 row affected (0.00 sec)
    MariaDB [(none)]> grant all on *.* to ken@'localhost' identified by '123';
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> exit
    Bye
     
    浏览器访问

  • 相关阅读:
    Java基础知识面试题(2021年最新版,持续更新...)整理
    windows10 cmd窗口输出卡住(看这篇就够了)
    windows10 powershell窗口输出卡住(看这篇就够了)
    Golang函数相关
    内存对齐详解
    Go编程模式Pipeline
    管道符、重定向与环境变量(Linux就该这么学第三章)
    GMP模型简介
    新手必须掌握的Linux命令(Linux就该这么学第二章)
    Goland运行项目报错:CreateProcess error=216, 该版本的 %1 与你运行的 Windows 版本不兼容。请查看计算机的系统信息,然后联系软件发布者。
  • 原文地址:https://www.cnblogs.com/itzhao/p/11360595.html
Copyright © 2020-2023  润新知