zoukankan      html  css  js  c++  java
  • Docker学习笔记

    Docker 学习笔记

    目录

    参考文档

    点击我跳转到 Docker 详细文档

    环境安装

    Mac安装Docker

    brew cask install docker
    

    Linux安装Docker

    # 使用 官方安装脚本自动安装
    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    
    # 国内专用
    curl -sSL https://get.daocloud.io/docker | sh
    

    Docker基础命令

    # 查看镜像
    docker images -a
    
    # 查看容器
    docker ps -a
    
    # 删除镜像
    docker rim xxxxx(容器id)
    
    # 删除容器
    docker rm xxxxx(容器id)
    
    # 使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。
    docker run -it nginx:latest /bin/bash
    
    # 启动一个或多个已经被停止的容器
    docker start
    
    # 停止一个运行中的容器
    docker stop
    
    # 重启容器
    docker restart
    
    # 进入容器 在容器 xxx 中开启一个交互模式的终端
    docker exec -it  xxx /bin/bash
    
    

    Docker 安装及部署 Mysql

    # docker 中下载 mysql
    docker pull mysql
    
    #启动
    docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=zhangds123!a -d mysql
    
    #进入容器
    docker exec -it mysql bash
    
    #登录mysql -设置root密码
    mysql -u root -p
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'zhangds123!a';
    
    #添加远程登录用户
    CREATE USER 'zhangds'@'%' IDENTIFIED WITH mysql_native_password BY 'zhangds123!';
    GRANT ALL PRIVILEGES ON *.* TO 'zhangds'@'%';
    
    # 重启
    docker restart xxxx(Docker id)
    
    

    Docker安装MQTT

    拉取 MQTT

    docker pull eclipse-mosquitto
    

    创建 MQTT 配置目录

    mkdir mqttConfig/config
    mkdir mqttConfig/data
    mkdir mqttConfig/log
    
    # 赋予 Log目录最大权限
    sudo chmod -R 777 mqttConfig/log
    
    

    创建配置文件

    # 配置文件
    touch mosquitto.conf
    

    内容如下:

        persistence true
        persistence_location /mosquitto/data
        log_dest file /mosquitto/log/mosquitto.log
    
        port 1883
        listener 9001
        protocol websockets
    
        # 关闭匿名模式
        allow_anonymous false
    
        # 指定密码文件
        password_file /mosquitto/config/pwfile.conf
    
        #备注:这里千万注意路径,指向的是 docker 的路径!!!(直接复制我的内容即可)
    

    创建用户名及密码文件

    touch pwfile.conf # 用户名及密码配置文件
    

    创建运行 Mosquitto 的脚本

    # 备注:请注意脚本的路径,请修改自己的脚本路径
    docker run -it --name=mqtt001 --privileged  -p 1883:1883 -p 9001:9001 -v /Users/bigbird/mqttConfig/config:/mosquitto/config/ -v /Users/bigbird/mqttConfig/data:/mosquitto/data -v /Users/bigbird/mqttConfig/log:/mosquitto/log -d  eclipse-mosquitto
    

    创建用户名和密码

    # 进入mosquitto容器
    docker exec -it xxxx(docker ID)  sh
    
    #对于passworf_file,可以复制一份模板,或者创建一个空文件
    touch /mosquitto/config/pwfile.conf
    chmod -R 755 /mosquitto/config/pwfile.conf
    
    # 使用mosquitto_passwd命令创建用户,第一个test是用户名,第二个test2019是密码
    mosquitto_passwd -b /mosquitto/config/pwfile.conf test test2019
    

    重启容器

    docker restart xxxx(Docker Id)
    

    MQTT 部署过程中出现的问题

    1592979788: Error: Unable to open log file /Users/bigbird/mqttconfig/mosquitto/log/mosquitto.log for writing.

    • 解决方法

      1.查看你的 mosquitto.conf 文件,路径是否正确!!! 这里的路径为 docker 的路径,千万别写成自己的路径!!!

        persistence true
        persistence_location /mosquitto/data
        log_dest file /mosquitto/log/mosquitto.log
      
        port 1883
        listener 9001
        protocol websockets
      
        # 关闭匿名模式
        allow_anonymous false
      
        # 指定密码文件
        password_file /mosquitto/config/pwfile.conf
      
        #备注:这里千万注意路径,指向的是 docker 的路径!!!(直接复制我的内容即可)
      

      2.文件权限问题, 对 mosquitto/log 赋予最高权限

        sudo chmod -R 777 mosquitto/log
      

    Docker搭建WebServer

    Docker搭建APIserver

    Docker实际使用中的注意事项及问题

  • 相关阅读:
    Linux0.11内核--fork进程分析
    Linux0.11内核--内存管理之1.初始化
    Linux0.11内核--进程调度分析之2.调度
    Linux0.11内核--进程调度分析之1.初始化
    github
    推荐大家一个靠谱的论文检测平台。重复的部分有详细出处以及具体修改意见,能直接在文章上做修改,全部改完一键下载就搞定了。他们现在正在做毕业季活动, 赠送很多免费字数,可以说是十分划算了!地址是:https://www.paperpass.com/
    妈妈再也不用担心我找idea激活码了
    eclipse集成tomcat
    DNS--localhost
    RFC 2819)第5节"Definitions"除外的全部内容
  • 原文地址:https://www.cnblogs.com/sjie/p/13189056.html
Copyright © 2011-2022 走看看