Docker安装Mysql-Java

一、安装mysql

前置条件:已安装部署完成docker环境

1.拉取镜像

[root@localhost ~]# docker pull mysql:5.7

5.7: Pulling from library/mysql
a076a628af6f: Pull complete
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1831ac1245f4: Pull complete
37677b8c1f79: Pull complete
27e4ac3b0f6e: Pull complete
7227baa8c445: Pull complete
Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

2.查看是否拉取正常

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 3 weeks ago 449MB
openzipkin/zipkin latest c0f8fe2f05f5 15 months ago 157MB
rabbitmq 3.8.0-management 5788d93cd8ad 15 months ago 180MB
hello-world latest fce289e99eb9 2 years ago 1.84kB
hub.c.163.com/springcloud/eureka latest 1472b2efca4f 2 years ago 190MB
redis 4.0.8 4760dc956b2d 2 years ago 107MB
rabbitmq 3.7.3-management 2f415b0e9a6e 2 years ago 151MB

3.运行mysql

[root@localhost ~]# sudo docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
WARNING: IPv4 forwarding is disabled. Networking will not work.
c828437a15ae88919653222bbe0bd950d0e9b3b0f38af5a18e8e0a0e16c14512

 

备注:

启动参数如下:

  • –name:容器名,此处命名为mysql
  • -e:配置信息,此处配置mysql的root用户的登陆密码
  • -p:端口映射,此处映射 主机3306端口 到 容器的3306端口
  • -d:后台运行容器,保证在退出终端后容器继续运行

建立目录映射如下:

docker run -p 3306:3306 --name mysql57 \
-v /opt/mysql/conf:/etc/mysql \
-v /opt/mysql/logs:/var/log/mysql \
-v /opt/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
  • -v:主机和容器的目录映射关系,":"前为主机目录,之后为容器目录

 二、安装JAVA

1.拉取镜像

[root@localhost docker]# docker pull openjdk:8

2.运行镜像

[root@localhost docker]# docker run -d -it --name java openjdk:8

3.java客户端

[root@localhost docker]# yum install -y java

posted @ 2021-02-14 20:39  Melek  阅读(882)  评论(0编辑  收藏  举报