docker学习笔记

步骤

uname -r 检查内核版本
yum install docker  安装docker
systemctl start docker //启动docker
docker -v //查看版本号
systemctl enable docker //docker开机启动
systemctl stop docker //停止docker
docker search mysql //搜索mysql镜像
docker pull mysql //下载mysql镜像
docker images //查看当前系统中镜像的状态
docker pull mysql:5.5 //5.5版本的镜像
docker rmi 29e0ae3b69b9 删除镜像

tomcat配置步骤

docker search tomcat //搜索镜像
docker pull tomcat //拉去镜像
docker run --name mytomcat -d tomcat:latest //启动容器  后台 版本
docker ps //查看运行中的容器
docker stop 0b09fbd875b0 //停止tomcat容器 容器ID
docker ps -a //查看所有容器 
docker start 0b09fbd875b0 //启动容器 容器ID
docker rm 0b09fbd875b0 //先停止容器,然后就可以删除容器了 容器ID
docker run -d -p 8888:8080 tomcat 启动容器
    -d表示后台运行
    -p表示主机8888端口映射到tomcat的8080端口
    这样启动以后,就可以外网:8888查看tomcat了,注意防火墙屏蔽端口
service firewalld status //查看防火墙状态
docker logs c6f0a631a540 //查看容器日志

mysql,redis,rabbitmq,elasticsearch安装步骤

docker pull mysql //下载镜像
docker run --name mysql01 -d mysql //启动容器
    这样启动容器并不能正常运行
    通过 `docker logs`可以看到说需要设置mysql的密码
    有问题的容器,直接`docker rm 78c308e8939f`删除
docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=123456 -d mysql//启动mysql容器
    mysql的root用户密码是123456
    由于没有做端口映射,所以也不能访问
docker run -p 3306:3306  --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
    端口号映射
    root密码
    后台运行

完整过程

huangchengdudeMacBook-Pro:docker huangchengdu$ docker run --name mysql -p 3308:3306 -e MYSQL_ROOT_PASSWORD=huang303513 -d mysql
1e3136fc1dcd96302404752543a78a853a7586cc1b089d5b9e854d002f41178d
huangchengdudeMacBook-Pro:docker huangchengdu$ docker exec -it mysql bash  
root@1e3136fc1dcd:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select host,user,plugin,authentication_string from mysql.user; 
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | caching_sha2_password | $A$005$8E<2 WTQ@   Pg-JqsD0/UA2DBLE8KDa/LqfF9FN.bWU2yYXtxnWtwtBc2 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$fam3B=^X9Otm>lDeyJqjqmQJg/jeSY/dUq8xerDX091FkOFUpE3jE0// |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

mysql> history
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'history' at line 1
mysql> create user 'huang303513'@'%' INENTIFIED BY 'huang303513';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INENTIFIED BY 'huang303513'' at line 1
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create user 'huang303513'@'%' IDENTIFIED BY 'huang303513';
Query OK, 0 rows affected (0.09 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

修改密码的模式

huangchengdudeMacBook-Pro:docker huangchengdu$ docker exec -it mysql bash  
root@1e3136fc1dcd:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select host,user,plugin,authentication_string from mysql.user; 
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
\_&ZzKovpgYEn7ImvChFqIo2NuI1ET89rb7ihjvtNdFkvpEB |word | $A$005$    "eXU,Y1R
| %         | root             | caching_sha2_password | $A$005$8E<2 WTQ@   Pg-JqsD0/UA2DBLE8KDa/LqfF9FN.bWU2yYXtxnWtwtBc2 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$fam3B=^X9Otm>lDeyJqjqmQJg/jeSY/dUq8xerDX091FkOFUpE3jE0// |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
6 rows in set (0.00 sec)

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | huang303513      | caching_sha2_password |
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)

mysql> mysql version
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql version' at line 1
mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 8.0.13                       |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| tls_version             | TLSv1,TLSv1.1,TLSv1.2        |
| version                 | 8.0.13                       |
| version_comment         | MySQL Community Server - GPL |
| version_compile_machine | x86_64                       |
| version_compile_os      | Linux                        |
| version_compile_zlib    | 1.2.11                       |
+-------------------------+------------------------------+
9 rows in set (0.01 sec)

mysql> ALTER user 'huang303513'@'%' IDENTIFIED WITH mysql_native_password BY 'huang303513';
Query OK, 0 rows affected (0.09 sec)

mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'huang303513';
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | huang303513      | mysql_native_password |
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)

mysql> 

你可能感兴趣的:(docker学习笔记)