docker后端基础环境搭建
docker利用dockerfile生成基础后端环境java8+git+maven创建dockerfile文件FROM centos:7RUN yum -y update \&& yum -y install vim \&& yum -y install git \&& yum -y install java-1.8.0-openjdk-devel.
docker利用dockerfile生成基础后端环境java8+git+maven
-
创建dockerfile文件
FROM centos:7 RUN yum -y update \ && yum -y install vim \ && yum -y install git \ && yum -y install java-1.8.0-openjdk-devel.x86_64 \ && yum install -y maven \ && mkdir ~/.m2 RUN echo '<?xml version="1.0" encoding="UTF-8"?><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><mirrors><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/repositories/central/</url></mirror></mirrors></settings>' > ~/.m2/settings.xml
-
在当前创建的dockerfile目录下
docker build -t java8pro .
-
根据镜像生成容器
docker run -it --name centos7Java8 java8pro bash
-
查看容器
docker ps
-
重启停止的容器
docker start 停止的容器id
-
docker对容器重命名
docker rename 原名称 新
docker安装mysql
-
安装
docker pull mysql:5.6
-
生成容器
docker run -p 3306:3306 --name mysql -v /project/mysql/conf:/etc/mysql/conf.d -v/project/mysql/logs:/logs -v/project/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Lzx15518947191. -d mysql:5.6
命令说明:
-p 3306:3306:将主机的3306端口映射到docker容器的3306端口。
–name mysql:运行服务名字
-v /project/mysql/conf:/etc/mysql/conf.d :将主机/project/mysql录下的conf/my.cnf 挂载到容器的 /etc/mysql/conf.d
-v /zzyyuse/mysql/logs:/logs:将主机/project/mysql目录下的 logs 目录挂载到容器的 /logs。
-v /zzyyuse/mysql/data:/var/lib/mysql :将主机/project/mysql目录下的data目录挂载到容器的 /var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。
-d mysql:5.6 : 后台程序运行mysql5.6
-
mysql设置密码
set password for root@localhost = password('123456');
-
mysql5.7时间戳问题
set sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
docker 安装redis
- 安装
docker pull redis:3.2
- redis启动
docker run -p 6379:6379 -v /project/myredis/data:/data -v /project/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf -d redis:3.2 redis-server /usr/local/etc/redis/redis.conf --appendonly yes
- redis 设置密码
redis-cli
config set requirepass 123456
docker容器中无法使用vim等命令
1. 更换apt-get的源 ,然后更行apt-get
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
-
安装yum
apt-get intall yum
- 通过yum可以进行其他的安装
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)