2020年7月

出现了一个诡异的问题, 在SQLyog中执行mysql连接是出现2058错误, 后面还有错误文字编码, 这个是由于加密方式导致的, SQLyog不支持mysql8的用户的默认加密方式

但是在一个开源的mysql工具中正常

解决方法:在命令行下登录 mysql -u root -p 登录你的 mysql 数据库然后 执行这条SQL

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

然后我在用SQLyog中再执行登录就正常了

先理解下概念

dockerfile用途是用于执行build生成镜像分支, 在依据这个镜像分支去运行多个镜像

下面以mysql举例

1. 拉取mysql镜像
docker pull mysql
2. 查看mysql
docker images |grep mysql
3.查看本地镜像: (参数-a 表示所有)
docker images -a 
  • 先创建一个Dockerfile文件
FROM mysql
EXPOSE 3306
ENV MYSQL_ROOT_PASSWORD 12345
  • 执行build命令
# 注意最后一个.不能少, 这个表示当前路径
[root@localhost mysql]# docker build -t mysql2:Dockerfile .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM mysql
 ---> be0dbf01a0f3
Step 2/3 : EXPOSE 3306
 ---> Running in 8f2ae74e3aae
Removing intermediate container 8f2ae74e3aae
 ---> 2a6324549f86
Step 3/3 : ENV MYSQL_ROOT_PASSWORD 12345
 ---> Running in 1c61b6fd498b
Removing intermediate container 1c61b6fd498b
 ---> ec33c8026d5c
Successfully built ec33c8026d5c
Successfully tagged mysql2:Dockerfile
  • 查询当前镜像, 这个mysql2就是以我们的配置构建的镜像分支
[root@localhost mysql]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
mysql2              Dockerfile          ec33c8026d5c        About a minute ago   541MB
mysql               latest              be0dbf01a0f3        3 weeks ago          541MB
  • 执行容器
docker run -p 3306:3306 --name my_mysql2 -e -d mysql2:Dockerfile --default-authentication-plugin=mysql_native_password

说明: --default-authentication-plugin=mysql_native_password 
这个配置的添加是为了保证启动好的mysql能通过sqlyog访问, 使用使用兼容的加密方式

这个方案并不好, 很傻, 主要是为了帮助理解dockerfile的简单的使用示例用途

让在textarea中按tab符号时输入4个空格, 使用时放于页面末尾即可

HTMLTextAreaElement.prototype.getCaretPosition = function () {
    //return the caret position of the textarea
    return this.selectionStart;
};
HTMLTextAreaElement.prototype.setCaretPosition = function (position) {
    //change the caret position of the textarea
    this.selectionStart = position;
    this.selectionEnd = position;
    this.focus();
};
HTMLTextAreaElement.prototype.hasSelection = function () {
    //if the textarea has selection then return true
    if (this.selectionStart == this.selectionEnd) {
        return false;
    } else {
        return true;
    }
};
HTMLTextAreaElement.prototype.getSelectedText = function () {
    //return the selection text
    return this.value.substring(this.selectionStart, this.selectionEnd);
};
HTMLTextAreaElement.prototype.setSelection = function (start, end) {
    //change the selection area of the textarea
    this.selectionStart = start;
    this.selectionEnd = end;
    this.focus();
};
var textarea = document.getElementsByTagName('textarea')[0];
textarea.onkeydown = function (event) {
    //support tab on textarea
    if (event.keyCode == 9) { //tab was pressed
        var newCaretPosition;
        newCaretPosition = textarea.getCaretPosition() + " ".length;
        textarea.value = textarea.value.substring(0, textarea.getCaretPosition()) + " " + textarea.value.substring(textarea.getCaretPosition(), textarea.value.length);
        textarea.setCaretPosition(newCaretPosition);
        return false;
    }
    if (event.keyCode == 8) {
        //backspace
        if (textarea.value.substring(textarea.getCaretPosition() - 4, textarea.getCaretPosition()) == " ") {
            //it's a tab space
            var newCaretPosition;
            newCaretPosition = textarea.getCaretPosition() - 3;
            textarea.value = textarea.value.substring(0, textarea.getCaretPosition() - 3) + textarea.value.substring(textarea.getCaretPosition(), textarea.value.length);
            textarea.setCaretPosition(newCaretPosition);
        }
    }
    if (event.keyCode == 37) { //left arrow
        var newCaretPosition;
        if (textarea.value.substring(textarea.getCaretPosition() - 4, textarea.getCaretPosition()) == " ") {
            //it's a tab space
            newCaretPosition = textarea.getCaretPosition() - 3;
            textarea.setCaretPosition(newCaretPosition);
        }
    }
    if (event.keyCode == 39) {
        //right arrow
        var newCaretPosition;
        if (textarea.value.substring(textarea.getCaretPosition() + 4, textarea.getCaretPosition()) == " ") {
            //it's a tab space
            newCaretPosition = textarea.getCaretPosition() + 3;
            textarea.setCaretPosition(newCaretPosition);
        }
    }
}

<!DOCTYPE html>
<html lang="utf8">
<head>
    <meta charset="UTF-8">
    <title>md转换为html</title>
</head>
<body>
<script src="https://cdn.bootcss.com/marked/0.8.0/marked.js"></script>
<link href="http://cdn.bootcss.com/highlight.js/8.0/styles/monokai_sublime.min.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/highlight.js/8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript">
    var rendererMD = new marked.Renderer();
    marked.setOptions({
        renderer: rendererMD,
        gfm: true,
        tables: true,
        breaks: false,
        pedantic: false,
        sanitize: false,
        smartLists: true,
        smartypants: false
    });
    marked.setOptions({
        highlight: function (code) {
            return hljs.highlightAuto(code).value;
        }
    });

    function insertText(obj, str) {
        if (document.selection) {
            var sel = document.selection.createRange();
            sel.text = str;
        } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
            var startPos = obj.selectionStart,
                endPos = obj.selectionEnd,
                cursorPos = startPos,
                tmpStr = obj.value;
            obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
            cursorPos += str.length;
            obj.selectionStart = obj.selectionEnd = cursorPos;
        } else {
            obj.value += str;
        }
    }

    function moveEnd(obj) {
        obj.focus();
        var len = obj.value.length;
        if (document.selection) {
            var sel = obj.createTextRange();
            sel.moveStart('character', len);
            sel.collapse();
            sel.select();
        } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
            obj.selectionStart = obj.selectionEnd = len;
        }
    }

    //ctrl 是dom节点
    function getCursortPosition(ctrl) {
        //获取光标位置函数
        var CaretPos = 0;
        // IE Support
        if (document.selection) {
            ctrl.focus(); // 获取焦点
            var Sel = document.selection.createRange(); // 创建选定区域
            Sel.moveStart('character', -ctrl.value.length); // 移动开始点到最左边位置
            CaretPos = Sel.text.length;                      // 获取当前选定区的文本内容长度
        }
        // Firefox support (非ie)
        else if (ctrl.selectionStart || ctrl.selectionStart == '0') {
            CaretPos = ctrl.selectionStart; // 获取选定区的开始点
        }
        return CaretPos;
    }

    //ctrl 是dom节点,pos 是要定位到的位置
    function setCaretPosition(ctrl, pos) {
        //设置光标位置函数
        if (ctrl.setSelectionRange)   //非ie
        {
            ctrl.focus();  // 获取焦点
            ctrl.setSelectionRange(pos, pos);  // 设置选定区的开始和结束点
        } else if (ctrl.createTextRange) {
            var range = ctrl.createTextRange();  // 创建选定区
            range.collapse(true);                // 设置为折叠,即光标起点和结束点重叠在一起
            range.moveEnd('character', pos);     // 移动结束点
            range.moveStart('character', pos);   // 移动开始点
            range.select();                      // 选定当前区域
        }
    }
</script>
<div style="font-size: 20px;height: 30px; text-align: center;color: #009689; font-weight: bold;">md转换为html</div>
<style type="text/css">
    #area > table {
        width: 100%;
        table-layout: fixed;
    }

    #area table tr td {
        margin: 0;
        padding: 6px;
        border: 0;
    }

    #md-area {
        width: 100%;
        height: 600px;
        font-size: 18px;
        overflow: hidden;
        font-weight: bold;
        outline: none;
    }

    #show-area {
        height: 600px;
        background-color: #FCF6E5;
    }

    .clearfix:before {
        content: "";
        display: table;
    }
</style>
<script>
    function mdSwitch() {
        var mdValue = document.getElementById("md-area").value;
        var html = marked(mdValue);
        document.getElementById("show-area").innerHTML = html;
    }

    function TextAreaTab(obj) {
        if (9 == event.keyCode) {
            //do stm...
            //alert(event.keyCode);
            var oldPos = getCursortPosition(obj);
            insertText(obj, "    ");
            setCaretPosition(obj, oldPos + 4);
            window.setTimeout(function () {
                //document.getElementById("bt0").click();
                obj.focus();
            }, 2);
        }
    }
</script>
<div id="area">
    <table>
        <tr>
            <td><textarea name="" id="md-area" onkeyup="mdSwitch()" onkeydown="TextAreaTab(this)"
                          autofocus="autofocus"></textarea></td>
            <td>
                <div id="show-area" class="clearfix"></div>
            </td>
        </tr>
    </table>
</div>
<button id="bt0">提交</button>
</body>
</html>

列出Docker本地所有镜像

docker images

下载镜像

# 下载ubuntu镜像
docker pull ubuntu
# 下载mysql镜像
docker pull mysql

停止和启动容器服务

[root@localhost ~]# systemctl stop docker
[root@localhost ~]# systemctl start docker

下载并运行 hyperf/hyperf 镜像,并将镜像内的项目目录绑定到宿主机的 /tmp/skeleton 目录

docker run -v /data/code:/data/code -p 80:9501 -it --entrypoint /bin/sh hyperf/hyperf:latest

docker run -v 主机路径:容器里面的路径 -p 主机端口:容器端口 -it --entrypoint /bin/sh (hyperf/hyperf:latest 镜像名:最新版本)

查看运行中的容器

docker ps

查看本地镜像: (参数-a 表示所有)

docker ps -a

进入容器

docker exec -it f54fc094edb2 /bin/bash

当容器中执行exit时自动重启

--restart=always

关闭容器

docker stop id

删除容器

docker rm -f 容器名
  • 通过容器名查询挂载配置信息
docker inspect 容器名| grep Mounts -A 20

➜  ~ docker inspect my_hyperf | grep Mounts -A 20
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/data/docker/code/fhx",
                "Destination": "/data/fhx",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/data/docker/code/wuloves",
                "Destination": "/data/wuloves",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "8898fabf14e8",
            "Domainname": "",

危险命令, 切勿在生产环境使用, 且使用前记得反复核对当前连接且关闭当前和非实验环境的连接

停止所有容器
docker stop $(docker ps -a -q) 
删除所有容器
docker rm $(docker ps -a -q)
删除所有镜像
docker rmi `docker images -a -q`
  • 当容器中没有 /bin/bash 时, 使用直接的 sh 就可以
[root@localhost ~]# docker exec -it etcd1 /bin/bash
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown

[root@localhost ~]# docker exec -it etcd1 sh
/ #