1、搭建Linux环境
Vagrant + VirtualBox + CentOS7 + WindTerm 5分钟搭建本地linux开发环境
2、安装Docker
- 清理Docker目录
shell
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 安装yum工具
shell
$ sudo yum install -y yum-utils
- 配置yum docker数据源
shell
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 配置阿里云加速
shell
$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ojy2ma14.mirror.aliyuncs.com"]
}
EOF
- 安装docker
shell
$ sudo yum install docker-ce docker-ce-cli containerd.io
- 启动Docker
shell
// 启动docker
$ sudo systemctl start docker
// 开机启动
$ sudo systemctl enable docker
// 重启
$ sudo systemctl restart docker
3、安装mysql
- 安装mysql
shell
[root@192 /]# docker search mysql
[root@192 /]# docker pull mysql
[root@192 /]# docker run -d --name mysql01 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 --privileged mysql
- 登陆mysql:进入到容器 => 登陆mysql => 执行mysql指令
shell
[root@192 /]# docker ps
[root@192 /]# docker exec -it [container_id]/bin/bash
root@83b5df689930:/# mysql -uroot -p
mysql> show databases;
mysql> create database user_data;
mysql> use user_data;
mysql> show tables;
- 将sql脚本从主机移动到docker容器(回到主机目录)
shell
docker cp [sqlname].sql [container]:/tmp
- 执行sql脚本(exec到容器执行)
java
mysql -u root -p < /tmp/[sqlname].sql
Tips:docker 常用指令
java
docker images
docker ps
docker ps -a
docker search [mysql/jdk/ngnix/...]
docker pull [image_name]
docker run --name [container_name] -p [ip]:[ip]
docker start [container_id]
docker stop [container_id]
docker rm -f [container_id]
docker rmi -f [image_id]