Docker常见应用部署(3)

 


1. Nginx

# 查询镜像
docker search nginx

# 拉取镜像
docker pull nginx

# 创建 nginx 容器,并将容器中的目录和宿主机目录进行挂载
docker run -di --name nginx -p 80:80 -v /mydata/docker_nginx/conf:/etc/nginx nginx

# 将容器内的配置文件拷贝到指定目录
docker cp nginx:/etc/nginx /mydata/docker-nginx/conf

# 重命名宿主机目录
mv /mydata/docker_nginx/nginx/ /mydata/docker-nginx/conf

2. MySQL

# 搜索镜像
docker search mysql

# 拉取镜像
docker pull mysql

# 创建容器
docker run -di --name mysql8 -p 3306:3306 -v /mydata/docker/mysql8/conf/my.cnf:/etc/mysql/my.cnf -v /mydata/docker/mysql8/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql

# 开机自启
docker update --restart=always 容器id

# docker desktop 运行镜像,挂载本地磁盘
# docker run -di --name mysql8 -p 3306:3306 -v D:/docker/mysql/config/my.cnf:/etc/mysql/my.cnf -v D:/docker/mysql/data:/var/lib/mysql --restart=always -e MYSQL_ROOT_PASSWORD=123456 mysql

# 进入容器
docker exec -it mysql8 bash

# 在容器内登录MySQL
mysql -u root -p

# 查看用户信息
select host,user,plugin,authentication_string from mysql.user;

# 备注:host 为 % 表示不限制 ip   localhost 表示本机使用    plugin 非 mysql_native_password 则需要修改密码
ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'system123456';
FLUSH PRIVILEGES;

-p :代表端口映射,格式为 宿主机映射端口:容器运行端口。
-e :代表添加环境变量 MYSQL_ROOT_PASSWORD 是 root 用户的登陆密码。连接容器中的 MySQL 时,只需要连接宿主机的 IP + 指定的映射端口即可。
注意:挂载本地磁盘时本地路径需要手动创建;本地配置文件不能为空,需要添加必要的配置信息比如如下配置:

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL

# Custom config should go here
!includedir /etc/mysql/conf.d/

3. RabbitMQ

# 拉取镜像
docker pull rabbitmq

# 创建容器
docker run -di --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq

# 进入容器
docker exec -it rabbitmq /bin/bash

# 开启管理界面
rabbitmq-plugins enable rabbitmq_management

访问地址查看是否安装成功 使用 guest 登录账号密码

posted @   shenghuotaiai  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示