1、制做本身的镜像java
1.前提mysql
2.制做步骤nginx
(1)下载Jpress https://github.com/JpressProjects/jpress 注意,是下载alpha分支的最新的war包git
(2)由于是java web项目,因此须要用到tomcat,咱们首先从网易镜像中心下载tomcat的镜像:github
C:\WINDOWS\system32>docker pull hub.c.163.com/library/tomcat:latest latest: Pulling from library/tomcat 9af7279b9dbd: Pull complete 31816c948f2f: Pull complete c59a1cdf83d3: Pull complete 232c7a75d568: Pull complete de412d312979: Pull complete 80315ba34693: Pull complete 5d3f97bd90e8: Pull complete dc8dc63f6baa: Pull complete f6c6e2d67f03: Pull complete 9123b340aa92: Pull complete 76abaea2279d: Pull complete 4476602e3346: Pull complete 12e1fda011bd: Pull complete Digest: sha256:db1a8ca2fe44449d265e5505f300be6f34fc63211a5506400a0a8c24653af91f Status: Downloaded newer image for hub.c.163.com/library/tomcat:latest C:\WINDOWS\system32>docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 05a3bd381fc2 7 weeks ago 1.84kB hub.c.163.com/library/tomcat latest 72d2be374029 2 months ago 292MB hub.c.163.com/library/nginx latest 46102226f2fd 6 months ago 109MB
(3)建立Dockerfile文件,将jpress.war文件移动到Dockerfile所在目录web
vi Dockerfile Doclerfile内容 from hub.c.163.com/library/tomcat #基础镜像的名字,以tomcat镜像为起点 MAINTAINER aibinxiao aibinxiao@126.com #镜像全部者信息 COPY jpress.war /usr/local/tomcat/webapps #将web应用放入tomcat服务器中,后面的目录在网易镜像中心的tomcat镜像的详情能够查看
(4)使用docker build -t jpress:latest .命令构建镜像,-t去个名字,jpress就是镜像名字,latest则是版本名称,.表示当前目录;到此镜像就制做好了。sql
docker build -t jpress:latest . Sending build context to Docker daemon 20.81 MB Step 1/3 : FROM hub.c.163.com/library/tomcat ---> c822d296d232 Step 2/3 : MAINTAINER aibinxiao aibinxiao@126.com ---> Using cache ---> 55e82dd26a32 Step 3/3 : COPY jpress.war /usr/local/tomcat/webapps ---> Using cache ---> 40e062337f9e Successfully built 40e062337f9e
(5)如何运行呢,咱们先作一个端口映射,咱们将本机的8888端口与jpress容器的8080端口,即tomcat端口进行映射,成功以后咱们就能够访问本地的8888端口,就能够进入到tomcat的主页了。docker
docker run -d -p 8888:8080 jpress 12fdb93345f253dd72766f6feada0aa7235dbfad2d030ebb8cad2adbc505363e
而后,咱们访问localhost:8888/jpress,就能进入jpress主页了,以下图:数据库
(5)可是要使用jpress,还须要数据库,咱们能够在docker里运行一个mysql浏览器
(6)一样是从网易镜像中心搜索mysql,复制mysql镜像的地址,先pull下来
docker pull hub.c.163.com/library/mysql:latest latest: Pulling from library/mysql 5047279b9dbd: Pull complete 31816c948f2f: Pull complete c59a1cdf83d3: Pull complete 232c7a75d568: Pull complete de412d312979: Pull complete 80315ba34693: Pull complete 5d3f97bd90e8: Pull complete dc8dc63f6baa: Pull complete f6c6e2d67f03: Pull complete 9123b340aa92: Pull complete 76abaea2279d: Pull complete 4476602e3346: Pull complete 12e1fda011bd: Pull complete Digest: sha256:84c78ca2fe44449d265e5505f300be6f34fc63211a5506400a0a8c24653af91f Status: Downloaded newer image for hub.c.163.com/library/msyql:latest
运行mysql
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=000000 -e MYSQL_DATABASE=jpress hub.c.163.com/library/mysql:latest 9305b93345f253dd72766f6feada0aa7235dbfad2d030ebb8cad2adbc505363e netstat -na|grep 3306 #查看该端口是否启用了
(7)配置数据库,注意数据库名就是启动mysql时配置的jpress,用户名root,密码000000,数据库主机则是本机的ip地址,端口3306
(8)配置网站信息
(9)重启jpress容器,再次在浏览器访问就完成了,以下图:
docker restart 12fdb93345f2
到此就所有结束啦!
本文为原创文章,若是对你有一点点的帮助,别忘了点赞哦!比心!如需转载,请注明出处,谢谢!