What is the method for docker to install mysql and redis images?
docker安装mysql、redis镜像
docker镜像商店:官方镜像商店
redis安装下载
下载镜像:
可直接默认下载最新镜像,也可以指定版本下载【注意,版本差异不大的软件可以直接下载最新版本,差异大的,例如java,mysql等,最好指定熟悉的版本进行下载】
docker pull redis
启动镜像:
docker run --name=redis -d --restart=always -p 6379:6379 redis
--name
:别名-d
:后台运行,镜像不会随窗口关闭而关闭--restart=always
:随docker启动而自启 可以进行后配置:docker update --restart=always [容器名称|id]-p
:6379[主机端口]:6379[映射端口],如果有版本号,应该带上版本号redis:6.2.6
挂载外部文件启动:
提前创建好文件夹和文件,redis.conf如果没有特别的配置,可以参考(测试环境,生产环境换成本地,关闭密码即可):
#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
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
修改配置文件 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
最后说一下文件外部挂载的优缺点:
优点:修改配置方便,不用每次都进入容器内部
缺点:外部挂载方式镜像将不可以打包传递
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
sudo yum install -y yum-utils //设置存储库
设置仓库地址,默认国外,也可以设置阿里云的
sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager \ --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docket引擎等组件
sudo yum install docker-ce docker-ce-cli containerd.io
启动docket
sudo systemctl start docker
配置加速镜像
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://chqac97z.mirror.aliyuncs.com"] } EOF
sudo systemctl daemon-reload sudo systemctl restart docker
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 '{print $1}'` //# 删除异常停止的容器 docker rmi -f `docker images | grep '<none>' | awk '{print $3}'` //删除名称或标签为none的镜像
使用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/
验证:用连接工具测试能不能连接成功,或window下cmd测试
ssh -v -h 3306 IP
使用docker安装Redis
docker pull redis:6.0.10 //拉取镜像
创建配置文件,docker-Redis里面默认没有配置文件,在宿主机创建并挂载到容器里
mkdir /home/redis cd /home/redis vi redis.conf
添加如下内容
bind 0.0.0.0 开启远程权限 appendonly yes 开启aof持久化
启动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客户端
安装nacos
拉取镜像
docker pull nacos/nacos-server
查看镜像
docker images
启动容器
docker run --env MODE=standalone --name mynacos -d -p 8848:8848 docker.io/nacos/nacos-server
查看启动日志
docker logs -f mynacos
日志中显示nacos服务地址为:
http://172.18.0.2:8848/nacos/index.html
默认账号密码都是nacos
进入nacos容器查看配置
docker ps docker exec -it 容器名或ID /bin/bash ls cd conf/ ls
修改启动配置文件
进入
docker exec -it nacos /bin/bash
进入启动脚本
cd /home/nacos/bin vim docker-startup.sh
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!

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.

Redis supports a variety of data structures, including: 1. String, suitable for storing single-value data; 2. List, suitable for queues and stacks; 3. Set, used for storing non-duplicate data; 4. Ordered Set, suitable for ranking lists and priority queues; 5. Hash table, suitable for storing object or structured data.

Redis counter is a mechanism that uses Redis key-value pair storage to implement counting operations, including the following steps: creating counter keys, increasing counts, decreasing counts, resetting counts, and obtaining counts. The advantages of Redis counters include fast speed, high concurrency, durability and simplicity and ease of use. It can be used in scenarios such as user access counting, real-time metric tracking, game scores and rankings, and order processing counting.

Use the Redis command line tool (redis-cli) to manage and operate Redis through the following steps: Connect to the server, specify the address and port. Send commands to the server using the command name and parameters. Use the HELP command to view help information for a specific command. Use the QUIT command to exit the command line tool.

Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.