云服务器Docker环境构建

@wanqiuz 2018-05-17 15:23:17发表于 wanqiuz/blog-articles

linux下文件结构

~/blog/db 用来存放应用的数据库
~/blog/app 用来存放应用的jar包

基于centos:7.4.1708生成mariadb镜像

docker run --privileged -itd --name blog_db -p 3307:3306 -v ~/blog/db:/var/lib/mysql centos:7.4.1708 /usr/sbin/init
docker exec -it [containerID] /bin/bash
yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
mysql -u root -p
> grant all privileges on *.* to 'root'@'%' identified by '[mysqlPassword]' with grant option;
> flush privileges;
// exit here
commit -m "centos:7.4.1708->mariadb" -a "wanqiu<zhaotree@126.com" [containerID] wanqiu/mariadb:1.0 

基于centos:7.4.1708生成jdk镜像

docker run -it centos:7.4.1708 /bin/bash
yum install -y wget
mkdir /var/tmp/jdk
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  -P /var/tmp/jdk http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz
tar xzf /var/tmp/jdk/jdk-8u172-linux-x64.tar.gz -C /var/tmp/jdk && rm -rf /var/tmp/jdk/jdk-8u172-linux-x64.tar.gz
下面参考
[Windows或Mac远程连接linux云服务器安装JDK](https://github.com/wanqiuz/blog-articles/issues/6)
安装nohup
yum -y install coreutils
commit -m "centos:7.4.1708->jdk" -a "wanqiu<zhaotree@126.com" [containerID] wanqiu/jdk:1.0

基于mariadb镜像生成数据库容器

docker run --privileged -itd --name blog_db -p 3307:3306 -v ~/blog/db:/var/lib/mysql [imageID] /usr/sbin/init
docker exec -it [containerID] /bin/bash

基于jdk镜像生成应用容器

docker run -it --name blog_app --link blog_db:db -p 80:80 -v ~/blog/app:/blog/app [imageID] /bin/bash
nohup java -jar blog/app/postblog-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --spring.datasource.url=jdbc:mysql://db:3306/dbarticle --server.port=80 --spring.datasource.password=[mysqlPassword] &

ps -ef 查看所有进程