目录

Life in Flow

知不知,尚矣;不知知,病矣。
不知不知,殆矣。

X

Docker部署博客系统

编写Dockerfile

[root@master software]# cat Dockerfile
FROM openjdk:8-jdk-alpine
MAINTAINER QingFeng
VOLUME /tmp
ADD kubeblog.jar /kubeblog.jar
EXPOSE 5000
ENTRYPOINT ["java","-jar","/kubeblog.jar"]

构建Docker镜像

[root@master software]# ls
Dockerfile kubeblog.jar  

# .代表当前路径
[root@master software]# docker build -t kubeblog:1.0 .
[root@master software]# docker images | grep kub
kubeblog            1.0                 ac3be2209d77        24 seconds ago      150MB

启动容器

[root@master software]# docker run --name kubeblog -d -p 5000:5000  --link mysql57 kubeblog:1.0

# 访问服务器
http://192.168.31.101:5000/about

进入容器查看环境变量

[root@master software]# docker exec -it kubeblog sh
/ # printenv
JAVA_ALPINE_VERSION=8.212.04-r0
HOSTNAME=ffd317827be4
MYSQL57_ENV_MYSQL_MAJOR=5.7
SHLVL=1
HOME=/root
MYSQL57_PORT_3306_TCP_ADDR=172.17.0.2
MYSQL57_ENV_MYSQL_ROOT_PASSWORD=password
MYSQL57_ENV_GOSU_VERSION=1.12
MYSQL57_PORT_3306_TCP_PORT=3306
JAVA_VERSION=8u212
MYSQL57_PORT_3306_TCP_PROTO=tcp
TERM=xterm
MYSQL57_PORT_33060_TCP_ADDR=172.17.0.2
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
MYSQL57_PORT=tcp://172.17.0.2:3306
MYSQL57_PORT_3306_TCP=tcp://172.17.0.2:3306
MYSQL57_PORT_33060_TCP_PORT=33060
MYSQL57_ENV_MYSQL_VERSION=5.7.30-1debian10
MYSQL57_PORT_33060_TCP_PROTO=tcp
MYSQL57_NAME=/kubeblog/mysql57
LANG=C.UTF-8
MYSQL57_PORT_33060_TCP=tcp://172.17.0.2:33060
JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
PWD=/


# 查看kubeblog容器的hosts文件
/ # cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      mysql57 747db6a0fb02
172.17.0.3      ffd317827be4


作者:Soulboy