docker安装mysql,tomcat,并且在tomcat可以访问到mysql
程序员文章站
2022-06-20 17:37:22
1.uname -an 查看当前系统版本 2.yum -y install docker 下载安装docker 3.service docker start 启动docker服务 4.docker version 检查docker是否安装成功 5.安装mysql,tomcat docker pull ......
1.uname -an 查看当前系统版本
2.yum -y install docker 下载安装docker
3.service docker start 启动docker服务
4.docker version 检查docker是否安装成功
5.安装mysql,tomcat
docker pull mysql:5.7.22,
docker pull tomcat:8
6.启动mysql
docker run -p 3306:3306 -e mysql_root_password=root -d --name mysql -v /data/mysql:/data -v /data/conf/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf mysql:5.7.22
如果出现 mysql 不存在之类的
执行 docker ps -a 或者 docker ps -l 显示 然后 docker rm id
7.启动 tomcat
docker run --name tomcat -d -p 8888:8080 tomcat:8
设置容器自启 sudo docker update --restart=always 8fb0ace2a24e
vim更换国内镜像地址
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list
echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
#更新安装源
apt-get update
#安装命令
apt-get install -y vim
查看容器ip
docker inspect mysql
"ipaddress": "172.17.0.3",
docker cp root.war 271ff0e62cf2:/usr/root.war docker复制文件
docker exec -it 271ff0e62cf2 /bin/bash 进入docker容器 或者 sudo docker exec -it 98af8be2b859 bash