一 安装mysql服务
1.1 拉取镜像1.拉取: docker pull mysql:5.7.29 2.查看镜像: docker images
1.2 在宿主机创建文件存储mysql1.创建映射目录:mysql-c5 在/root/export/dockertest 目录下,mkdir -p mysql-c5 ;映射mysql信息
1.3 创建容器docker run -id --privileged=true /-p 3306:3306 /--name=c5_mysql /-v $PWD/conf:/etc/mysql/conf.d /-v $PWD/logs:/logs /-v $PWD/data:/var/lib/mysql /-e MYSQL_ROOT_PASSWORD=123456 /mysql:5.7.29
1.4 进入容器root@localhost dockertest]# docker exec -it c5_mysql /bin/bashroot@5d6f5def65ce:/# mysql -uroot -p123456mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 2Server version: 5.7.29 MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '/h' for help. Type '/c' to clear the current input statement. mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.00 sec)
1.5 远程连接
二 微服务工程
2.1 微服务工程创建配置连接: 3.访问
三 docker-compose 下载安装
3.1 docker-compose的安装1.、安装Docker Compose # Compose目前已经完全支持Linux、Mac OS和Windows,在我们安装Compose之前,需要先安装Docker。下面我 们以编译好的二进制包方式安装在Linux系统中。 curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose 2. 设置文件可执行权限 chmod +x /usr/local/bin/docker-compose 3.查看版本信息 docker-compose -version 4.卸载Docker Compose 二进制包方式安装的,删除二进制文件即可 rm /usr/local/bin/docker-compose
四 编写docker-compose文件
4.1 将jar包上上传到服务器
五 docker网络
5.1 创建网络创建网络,让容器之间可以进行互通访问。 [root@localhost docker-compose-dir]# docker network lsNETWORK ID NAME DRIVER SCOPEfe668cbe4240 bridge bridge localead95c34bb4d host host local2452f37044ee none null local[root@localhost docker-compose-dir]# docker network create ljf_netd9e1593ce665508aa690393a6976ce4165669cbee93c65645fc6056d8765b737[root@localhost docker-compose-dir]# docker network lsNETWORK ID NAME DRIVER SCOPEfe668cbe4240 bridge bridge localead95c34bb4d host host locald9e1593ce665 ljf_net bridge local2452f37044ee none null local 2 截图 编写将jar包打成镜像 ,编写dockerfile文件,这里存储位置为: /root/export/dockertest/docker-compose-dir 创建dockfile文件: vim spt04-dockerfile 内容如下: #基础镜像使用javaFROM java:8#作者MAINTAINER ljf#volume 制定临时文件目录为/tmp,VOLUME /tmp#将jar包添加到容器中并更名为spt-docker。jarADD 04-spt-mybaitsplus-fenye-1.0-SNAPSHOT.jar 04-spt-fenye.jar#运行jar包ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","04-spt-fenye.jar"]#暴露端口8080作为微服务EXPOSE 8084 [root@localhost docker-compose-dir]# ls04-spt-mybaitsplus-fenye-1.0-SNAPSHOT.jar spt04-dockerfile[root@localhost docker-compose-dir]# pwd/root/export/dockertest/docker-compose-dir[root@localhost docker-compose-dir]# vi spt04-dockerfile [root@localhost docker-compose-dir]# 打成镜像: docker build -f spt04-dockerfile -t 04-spt-fenye-master:1.6 . 查看镜像: docker images 下载地址: Vmware虚拟机磁盘映射到本地实现文件传输的实现 Docker-compose搭建Redis集群(Sentinel)的实现 |