yum install docker
前置条件:系统为centos7.x
----docker启动时挂载本地路径-------
--------这样做的好处就是日志和容器app都是存本地,不会在镜像重启后,重置容器中的东西------------
docker pull tomcat
docker run --name tomcat -itd --rm -p 8080:8080 -v /usr/local/tomcat/webapps:/usr/local/tomcat/webapps -v /usr/local/tomcat/logs:/usr/local/tomcat/logs tomcat
--------------------------------------------------------------------------------------
1.docker pull nginx
2.docker run -d --name nginx00 -p 80:80 nginx
3.建立nginx本地文件映射目录
cd /usr/local/nginx
mkdir html
mkdir logs
docker container cp nginx00:/etc/nginx .
mv nginx conf
4.停止原来的容器
docker stop nginx00 #停止
docker rm nginx00 #删除
docker ps -a #看看是不是没了
5.docker run -d -p 80:80 --name nginx01 -v /usr/local/nginx/html:/usr/share/nginx/html -v /usr/local/nginx/conf:/etc/nginx -v /usr/local/nginx/logs:/var/log/nginx nginx
6.以上黄色去背景位置为本地,html静态文件放到该目录下
--------docker 挂载postgresql---------------
docker run -it --name postgres --restart always -e POSTGRES_PASSWORD='abc123' -e ALLOW_IP_RANGE=0.0.0.0/0 -v /usr/local/postgres/:/var/lib/postgresql -p 5432:5432 -d postgres
--------docker 挂载mysql---------
1.docker run -p 3306:3306 -v /usr/local/mysql/conf/conf.d:/etc/mysql/conf.d -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/logs:/logs -e MYSQL_ROOT_PASSWORD=abc123 -e TZ=Asia/Shanghai --name mysql -d mysql:latest
2.docker exec -it mysql /bin/bash
3.mysql -uroot -p
4.ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'abc123';
5.flush privileges;
--------docker 挂载redis---------
docker run -d -p 6379:6379 -v /usr/local/redis/data:/data redis