Docker安装mysql
查找docker hub上的镜像
docker search mysql
拉取镜像
docker pull mysql:latest
运行容器
docker run -p 3306:3306 \
--name mysql \
-v /data/mysql/conf:/etc/mysql/conf.d \
-v /data/mysql/logs:/logs \
-v /data/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:latest
进入容器并操作
docker exec -it mysql /bin/bash
#mysql -uroot -p
#输入密码123456
mysql>show databases;
mysql>create database db01;
mysql>use db01;
mysql>create table t_book(id int not null primary key, bookName varchar(50));
mysql>show tables;
mysql>insert into t_book values(1,'Java');
使用客户端连接mysql,并修改数据进行验证。
mysql数据备份
docker exec mysql sh -c ’ exec mysqldump --all-databases -uroot -p “123456” '>/data/all-databases.sql
Docker安装Redis
docker pull redis
docker run -p 6379:6379 \
--name redis \
-v /data/redis/data:/data \
-v /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-d redis redis-server /usr/local/etc/redis/redis.conf \
--appendonly yes
Docker安装Tomcat
docker search tomcat
docker pull tomcat
docker run -d -p 8080:8080 mytomcat tomcat
#访问http:localhost:8080/报错404时
进入容器docker exec -it mytomcat bash
rm -rf webapps
mv webapps.dist webapps
直接下载装了jdk8的镜像
docker pull billygoo/tomcat8-jdk8
docker run -d -p 8080:8080 --name mytomcat8 billygoo/tomcat8-jdk8
镜像推送到阿里云
sudo docker login --username=registry.cn-hangzhou.aliyuncs.com
sudo docker tag [imageIs] registry.cn-hangzhou.aliyuncs.com/hukl/mycentos:[镜像版本号]
sudo docker push registry.cn-hangzhou.aliyuncs.com/hukl/mycentos:[镜像版本号]