Table of Contents
docker安装mysql、redis镜像
redis安装下载
mysql安装下载
docker安装使用及用docker安装mysql,Redis,nacos
安装
docket常用命令
使用docker安装MySQL
使用docker安装Redis
安装nacos
修改启动配置文件
Home Database Redis What is the method for docker to install mysql and redis images?

What is the method for docker to install mysql and redis images?

May 26, 2023 pm 08:16 PM
mysql redis docker

    docker安装mysql、redis镜像

    docker镜像商店:官方镜像商店

    redis安装下载

    下载镜像:

    What is the method for docker to install mysql and redis images?

    What is the method for docker to install mysql and redis images?

    可直接默认下载最新镜像,也可以指定版本下载【注意,版本差异不大的软件可以直接下载最新版本,差异大的,例如java,mysql等,最好指定熟悉的版本进行下载

    docker pull redis
    Copy after login

    启动镜像:

    docker run --name=redis -d --restart=always -p 6379:6379 redis
    Copy after login
    • --name:别名

    • -d:后台运行,镜像不会随窗口关闭而关闭

    • --restart=always:随docker启动而自启 可以进行后配置:docker update --restart=always [容器名称|id]

    • -p:6379[主机端口]:6379[映射端口],如果有版本号,应该带上版本号redis:6.2.6

    挂载外部文件启动:

    提前创建好文件夹和文件,redis.conf如果没有特别的配置,可以参考(测试环境,生产环境换成本地,关闭密码即可):

    What is the method for docker to install mysql and redis images?

    #redis使用自定义配置文件启动
     
    docker run -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
    -v /mydata/redis/data:/data \
    -d --name redis \
    --restart=always \
    -p 6379:6379 \
    redis:latest  redis-server /etc/redis/redis.conf
     
    #最后这一句代表自启动方式,redis启动默认不加载此处配置
    redis-server /etc/redis/redis.conf
    Copy after login

    mysql安装下载

    镜像参考redis直接下载对应版本即可。

    -v:配置挂载,冒号左边为容器内部想要挂载出去的配置路径,右边为挂载的实际路径

    例如:mysql,挂载日志,数据,配置等信息到外部

    docker run -p 3306:3306 --name mysql \
    -v /mydata/mysql/log:/var/log/mysql \
    -v /mydata/mysql/data:/var/lib/mysql \
    -v /mydata/mysql/conf/my.cnf:/etc/mysql/my.cnf \
    -e MYSQL_ROOT_PASSWORD=root \
    -d mysql:5.7
    Copy after login

    修改配置文件 my.cnf

    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8
    [mysqld]
    init_connect='SET collation_connection = utf8_unicode_ci'
    init_connect='SET NAMES utf8'
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    skip-character-set-client-handshake
    skip-name-resolve
    lower_case_table_names=1
    Copy after login

    最后说一下文件外部挂载的优缺点:

    • 优点:修改配置方便,不用每次都进入容器内部

    • 缺点:外部挂载方式镜像将不可以打包传递

    docker安装使用及用docker安装mysql,Redis,nacos

    安装

    卸载之前的docket

    sudo yum remove docker \
                       docker-client \
                       docker-client-latest \
                       docker-common \
                       docker-latest \
                       docker-latest-logrotate \
                       docker-logrotate \
                       docker-engine
    Copy after login
    sudo yum install -y yum-utils  //设置存储库
    Copy after login

    设置仓库地址,默认国外,也可以设置阿里云的

    sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
    Copy after login
    yum-config-manager \
        --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    Copy after login

    安装docket引擎等组件

    sudo yum install docker-ce docker-ce-cli containerd.io
    Copy after login

    启动docket

    sudo systemctl start docker
    Copy after login

    配置加速镜像

    sudo mkdir -p /etc/docker
    Copy after login
    sudo tee /etc/docker/daemon.json <<-&#39;EOF&#39;
    {
      "registry-mirrors": ["https://chqac97z.mirror.aliyuncs.com"]
    }
    EOF
    Copy after login
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    Copy after login

    docket常用命令

    systemctl stop docker //关闭docker
    systemctl restart docker //重启docker
    systemctl status docker  //查看docker状态
    systemctl enable docker  //设置docker开机自启动
    
    docker images  //查看自己服务器的镜像列表
    docker search 镜像名  //搜索指定镜像
    docker search --filter=STARS=9000 mysql  //搜索 STARS >9000的 mysql 镜像
    docker pull 镜像名 //拉取docker仓库里的镜像
    docker pull 镜像名:tag  //拉取docker仓库里指定版本的镜像,具体版本号需要到镜像官网查看(https://hub.docker.com/search?type=image)
    docker pull mysql 5.7.30 //拉取5.7.30的mysql
    docker run 镜像名  //运行镜像
    docker run 镜像名:Tag  //运行指定版本的镜像
    
    docker rmi -f 镜像名/镜像ID //删除一个镜像,镜像没有被别的镜像使用才可以删除
    docker rmi -f 镜像名/镜像ID 镜像名/镜像ID 镜像名/镜像ID  //删除多个镜像,空格隔开
    docker rmi -f $(docker images -aq) //删除全部镜像  -a 意思为显示全部, -q 意思为只显示ID
    docker image rm 镜像名称/镜像ID  //强制删除镜像
    
    docker save 镜像名/镜像ID -o 镜像保存在哪个位置与名字
    docker save tomcat -o /myimg.tar //保存Tomcat到myimg.tar里
    docker commit -m="提交信息" -a="作者信息" 容器名/容器ID 提交后的镜像名:Tag
    
    docker ps  //查看正在运行容器列表
    docker ps -a  //查看所有容器 -----包含正在运行 和已停止的
    docker exec -it 容器名 路径//进入容器 里的路径
    #删除一个容器
    docker rm -f 容器名/容器ID
    #删除多个容器 空格隔开要删除的容器名或容器ID
    docker rm -f 容器名/容器ID 容器名/容器ID 容器名/容器ID
    #删除全部容器
    docker rm -f $(docker ps -aq)
    docker start 容器ID/容器名  //启动容器
    docker stop 容器ID/容器名    //停止容器
    docker restart 容器ID/容器名    //重启容器
    docker kill 容器ID/容器名  //kill 容器
    
    docker cp 容器ID/名称: 容器内路径  容器外路径        //容器内拷文件到外面
    docker cp 容器外路径 容器ID/名称: 容器内路径        //容器外拷文件到容器内
    docker run -it -d --name 容器别名 镜像名 --restart=always   //容器随着docker启动而启动
    docker update --restart=always 容器Id 或者 容器名 //修改容器启动配置(设置自启动)
    docker rename 容器ID/容器名 新容器名  //更改容器名
    
    docker logs container-id    //查看容器日志
    sudo docker info | grep "Docker Root Dir"  //查看docker工作目录
    du -hs /var/lib/docker/     //查看docker磁盘占用总体情况
    docker system df    //查看Docker的磁盘使用具体情况
    docker rm `docker ps -a | grep Exited | awk &#39;{print $1}&#39;`  //#  删除异常停止的容器
    docker rmi -f  `docker images | grep &#39;<none>&#39; | awk &#39;{print $3}&#39;` //删除名称或标签为none的镜像
    Copy after login

    使用docker安装MySQL

    sudo docker pull mysql:5.7.39  //拉取mysql镜像到本地
    # --name指定容器名字 -v目录挂载 -p指定端口映射(宿主机端口:容器端口)  -e设置mysql参数 -d后台运行
    sudo docker run --name mysql -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/conf:/etc/mysql -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/mysql-files:/var/lib/mysql-files/  -e MYSQL_ROOT_PASSWORD=root  -p 3306:3306 -d mysql:5.7
    docker exec -it 容器名称|容器id bin/bash  //进入容器里
    exit  //退出容器
     -v /usr/local/mysql/mysql-files:/var/lib/mysql-files/
    Copy after login

    验证:用连接工具测试能不能连接成功,或window下cmd测试

    ssh -v -h 3306 IP
    Copy after login

    使用docker安装Redis

    docker pull redis:6.0.10  //拉取镜像
    Copy after login

    创建配置文件,docker-Redis里面默认没有配置文件,在宿主机创建并挂载到容器里

    mkdir /home/redis
    cd /home/redis
    vi redis.conf
    Copy after login

    添加如下内容

    bind 0.0.0.0  开启远程权限
    appendonly yes  开启aof持久化
    Copy after login

    启动Redis容器并挂载文件

    docker run --name redis  -v /home/redis/data:/data  -v /home/redis/redis.conf:/usr/local/etc/redis/redis.conf -p 6379:6379 -d redis:6.0.10  redis-server /usr/local/etc/redis/redis.conf
    docker exec -it redis redis-cli //进入Redis客户端
    Copy after login

    安装nacos

    拉取镜像

    docker pull nacos/nacos-server
    Copy after login

    查看镜像

    docker images
    Copy after login

    启动容器

    docker run --env MODE=standalone --name mynacos -d -p 8848:8848 docker.io/nacos/nacos-server
    Copy after login

    查看启动日志

    docker logs -f mynacos
    Copy after login

    日志中显示nacos服务地址为:

    http://172.18.0.2:8848/nacos/index.html

    默认账号密码都是nacos

    进入nacos容器查看配置

    docker ps
    docker exec -it 容器名或ID /bin/bash
    ls
    cd conf/
    ls
    Copy after login

    修改启动配置文件

    进入

    docker exec -it nacos /bin/bash
    Copy after login

    进入启动脚本

    cd /home/nacos/bin
    vim docker-startup.sh
    Copy after login

    The above is the detailed content of What is the method for docker to install mysql and redis images?. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    Java Tutorial
    1664
    14
    PHP Tutorial
    1268
    29
    C# Tutorial
    1243
    24
    MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

    MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

    Redis's Role: Exploring the Data Storage and Management Capabilities Redis's Role: Exploring the Data Storage and Management Capabilities Apr 22, 2025 am 12:10 AM

    Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

    How do containerization technologies (like Docker) affect the importance of Java's platform independence? How do containerization technologies (like Docker) affect the importance of Java's platform independence? Apr 22, 2025 pm 06:49 PM

    Containerization technologies such as Docker enhance rather than replace Java's platform independence. 1) Ensure consistency across environments, 2) Manage dependencies, including specific JVM versions, 3) Simplify the deployment process to make Java applications more adaptable and manageable.

    Docker on Linux: Containerization for Linux Systems Docker on Linux: Containerization for Linux Systems Apr 22, 2025 am 12:03 AM

    Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

    Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

    In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

    Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

    The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

    SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

    SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

    Redis: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

    Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

    See all articles