win10下安装使用Docker:Docker for Windows

一、下载win10下安装docker和桌面管理的工具:

下载地址:Docker for Windows

安装软件学习地址:https://www.runoob.com/docker/docker-tutorial.html

  下载完是一个安装程序,双击运行即可。cmd命令就可以开始使用docker安装需要的软件镜像了。

(特别提醒:1、安装此程序后,VMware安装centos会报错,所以只能二选一。0.0我也很苦恼。

      2、方便是真的方便,但很占用内存,这是真没VMware厉害。      

)

 

二、下载完成后,安装redis、mysql、MongoDB、

  2-1:安装redis

    访问 Redis 镜像库地址: https://hub.docker.com/_/redis?tab=tags

#按装redis镜像
$ docker pull redis:latest

#查看镜像
$ docker images

#启动容器
$ docker run -itd --name redis-test -p 6379:6379 redis

  2-2:安装mysql

    访问 MySQL 镜像库地址:https://hub.docker.com/_/mysql?tab=tags 。

#拉取mysql镜像
$ docker pull mysql:latest

#查看安装镜像
$ docker images

#启动docker容器
$ docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql    

  参数说明:

  •  -p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。
  • MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 root 用户的密码      

 注意: 安装好mysql后,还要进入mysql进行远程连接配置(不然远程连接时会报错)

  1、进入mysql

1 docker exec -it mysql bash  
2 root@a42f31094df5:/#  

  2、在容器内登陆Mysql:

 1 root@a42f31094df5:/# mysql -uroot -p123456 或 (mysql -uroot -p ) 
 2 mysql: [Warning] Using a password on the command line interface can be insecure.  
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.  
 4 Your MySQL connection id is 9  
 5 Server version: 8.0.11 MySQL Community Server - GPL  
 6   
 7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.  
 8   
 9 Oracle is a registered trademark of Oracle Corporation and/or its  
10 affiliates. Other names may be trademarks of their respective  
11 owners.  
12   
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
14   
15 mysql>   

      3、查看用户信息

mysql> select host,user,plugin,authentication_string from mysql.user; 

备注:host为 % 表示不限制ip   localhost表示本机使用    plugin非mysql_native_password 则需要修改密码navicat链接错误;我们继续往下看;

1 mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';  
2 Query OK, 0 rows affected (0.01 sec)  
3 mysql>   
4 mysql> FLUSH PRIVILEGES;  
5 Query OK, 0 rows affected (0.01 sec)  
6   
7 mysql>   

     4、使用navicat连接docker下载的mysql成功。。。

  2-3、安装MongoDB

    访问 MongoDB 镜像库地址: https://hub.docker.com/_/mongo?tab=tags&page=1

#拉取镜像
$ docker pull mongo:latest

#配置启动容器
$ docker run -itd --name mongo -p 27017:27017 mongo --auth

  参数说明:

  • -p 27017:27017 :映射容器服务的 27017 端口到宿主机的 27017 端口。外部可以直接通过 宿主机 ip:27017 访问到 mongo 的服务。
  • --auth:需要密码才能访问容器服务。(如果是自己使用,建议不要加 --auth)
$ docker exec -it mongo mongo admin
# 创建一个名为 admin,密码为 123456 的用户。
>  db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
# 尝试使用上面创建的用户信息进行连接。
> db.auth('admin', '123456')

 

  三、使用docker下载好的软件,同时也可以在安装的Docker for Windows的Docker Desktop管理启动、停止、删除等,如下图:

 

四、使用dcoker拉取镜像时因为是国外地址比较慢,可以使用阿里云加速(https://blog.csdn.net/kozazyh/article/details/79511723);

    将获得的加速网址配置如下:

 

posted @ 2020-06-03 10:12  糊涂蜗牛  阅读(5681)  评论(0编辑  收藏  举报