docker學習筆記

步驟

uname -r 檢查內核版本
brew cask 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學習筆記(一)Docker初體驗 什么是Docker Docker是一個虛擬環境容器,可以將開發環境、...
    陳豐堯閱讀 1,055評論 0 1
  • 轉載自 http://blog.opskumu.com/docker.html 一、Docker 簡介 Docke...
    極客圈閱讀 10,532評論 0 120
  • Docker 和虛擬機 容器內的進程是直接運行于宿主內核的,這點和宿主進程一致,只是容器的 userland 不同...
    Jancd閱讀 509評論 0 8
  • docker是一個能夠把開發的應用程序自動部署到容器的開源引擎 docker依賴于寫時復制模型 docker客戶端...
    Broom閱讀 1,787評論 0 0
  • 二胎熱議,許多70后家長摩拳擦掌想第二次做父母。我有一個8歲的弟弟,小我12歲,趕在開放二胎前的最后一批超生的家庭...
    吃土少女的的閱讀 372評論 0 1