1、搭建Linux环境
Vagrant + VirtualBox + CentOS7 + WindTerm 5分钟搭建本地linux开发环境
2、安装Docker
- 清理Docker目录
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 安装yum工具
$ sudo yum install -y yum-utils
- 配置yum docker数据源
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 配置阿里云加速
$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ojy2ma14.mirror.aliyuncs.com"]
}
EOF
- 安装docker
$ sudo yum install docker-ce docker-ce-cli containerd.io
- 启动Docker
// 启动docker
$ sudo systemctl start docker
// 开机启动
$ sudo systemctl enable docker
// 重启
$ sudo systemctl restart docker
3、安装mysql
- 安装mysql
[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指令
[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容器(回到主机目录)
docker cp [sqlname].sql [container]:/tmp
- 执行sql脚本(exec到容器执行)
mysql -u root -p < /tmp/[sqlname].sql
Docker 常用指令
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]
完整卸载Docker
systemctl status docker
systemctl stop docker
yum list installed |grep docker
rpm -qa |grep docker
yum -y remove 第三步中的文件名
rm -rf /var/lib/docker
docker version