Docker的镜像文件可以在镜像仓库中进行搜索。
部署软件目录导航:
docker的常用命令如下:
具体的执行命令,还可以去参考镜像仓库对应镜像的详细介绍。
下载Tomcat镜像文件,如下命令会下载latest版本的tomcat。
[root@localhost ~]# docker pull tomcat
下载完成后可以使用 docker images 查看下载后的镜像文件信息。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest df50c9d355cf 6 days ago 463 MB
启动tomcat程序,如下命令会在后台执行tomcat。并将tomcat默认的8080端口指向系统的8080端口。
[root@localhost ~]# docker run -d -p 8080:8080 tomcat
如果想打开多个Tomcat则直接,如上一样的名并将8080端口改为8081则,两个tomcat互不干扰,可同时存在。
docker run -d -p 8081:8080 tomcat
使用docker ps 查看正在运行的程序
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d64f362c40a tomcat "catalina.sh run" 8 seconds ago Up 7 seconds 0.0.0.0:8081->8080/tcp gracious_bohr
39d01b39e8d3 tomcat "catalina.sh run" 4 minutes ago Up 4 minutes 0.0.0.0:8080->8080/tcp wizardly_davinci
其中有两个Tomcat程序。如下访问结果:
下载最新版Mysql。
[root@localhost ~]# docker pull mysql
查看镜像是否下载成功。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest df50c9d355cf 6 days ago 463 MB
docker.io/mysql latest 8d99edb9fd40 6 days ago 445 MB
启动镜像文件,执行如下命令,会在后台启动mysql,暴露3306端口,并命名为 my-mysql 且设置root密码为123456。
[root@localhost ~]# docker run -p 3306:3306 --name my-mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
执行如下命令可以进入mysql 的 client。第一条 docker exec -it my-mysql bash。 可以进入到mysql的bash shell界面,然后执行 mysql -uroot -p是输入密码即可进入到mysql client。
[root@localhost ~]# docker exec -it my-mysql bash
root@f3f79ca4eae1:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 8.0.11 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>
可以通过日志看到安装的 mysql 版本是 8.0.11。这个版本使用navicat连接时,会报如下错误:
执行select host, user, authentication_string, plugin from user;命令可以查询
导致如上问题就是因为 'root'@'%' 的密码加密方式 使用的是 caching_sha2_password。我们需要修改它的加密方式。
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | $Amysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.09 sec)
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+-------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+-------------------------------------------+-----------------------+
| % | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password |
| localhost | mysql.infoschema | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password |
+-----------+------------------+-------------------------------------------+-----------------------+
5 rows in set (0.00 sec)
5$bx9?Rgb:Y0&7q7:;Ef8isqjh0JQzsp6bJXk4eL/ibgbXx8zwdntsl0qxGA8 | caching_sha2_password |
| localhost | mysql.infoschema | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mysql_native_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)
执行如下命令进行修改加密方式。
部署 Oracle
执行完毕后查看加密方式已修改,现使用navicat连接测试如下。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest df50c9d355cf 6 days ago 463 MB
docker.io/mysql latest 8d99edb9fd40 7 days ago 445 MB
docker.io/wnameless/oracle-xe-11g latest 698cc7361de4 5 weeks ago 2.13 GB
第一步还是下载Oracle数据库镜像仓库搜索的oracle 11g 可以找到 wnameless/oracle-xe-11g 镜像文件。
[root@localhost ~]# docker pull wnameless/oracle-xe-11g
查看下载后的镜像文件有2.13GB,比较大。
[root@localhost ~]# docker run --name oracle -d -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g
启动命令如下:
hostname: localhost
port: 1521
sid: xe
username: system
password: oracle
SYS&SYSTEM的密码
oracle
默认用户信息如下:
测试效果如下: