Docker 实战之jpress博客部署

2017年8月29日22:23:03 发表评论 2,054 views

Docker 实战之jpress博客部署

一、安装docker(centos6.8)

Docker官网:https://docs.docker.com/

系统版本

[root@bogon yum.repos.d]# uname -a

Linux bogon 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@bogon yum.repos.d]# cat /etc/redhat-release

CentOS release 6.8 (Final)

安装EPEL

因为系统自带的repo中不带docker需要安装epel

rpm -Uvh http://ftp.riken.jp/Linux/fedora/epel/6Server/x86_64/epel-release-6-8.noarch.rpm

安装Docker

yum install -y docker-io

开机自启动与启动Docker

[root@bogon yum.repos.d]# service docker start

Starting cgconfig service:                                 [  OK  ]

Starting docker:                                       [  OK  ]

[root@bogon yum.repos.d]# chkconfig docker on

[root@bogon yum.repos.d]# chkconfig docker --list

docker          0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@bogon yum.repos.d]#

至此docker已经安装完成

 

二、用docker做JPress镜像,运行JRress镜像和MYsql镜像

开源博客平台:  http://jpress.io/  

网易蜂巢镜像:https://c.163.com/product/service

https://c.163.com/hub#/m/home/

准备jpress包。在官网下载http://jpress.io/  到本地

Docker 实战之jpress博客部署

Docker 实战之jpress博客部署

 Docker 实战之jpress博客部署

 

# wget https://github.com/JpressProjects/jpress/blob/alpha/wars/jpress-web-newest.war

[root@zhang ~]# mv jpress-web-newest.war jpress.war   (方便记忆)

  • 启动docker

[root@zhang ~]# service docker start

[root@zhang ~]# ps -ef | grep docker

root      2347     1  0 18:46 ?        00:00:01 /usr/bin/docker -d

root      4018  3974  0 21:17 pts/1    00:00:00 grep docker

[root@zhang ~]# docker pull hub.c.163.com/library/tomcat:latest

[root@zhang ~]# docker pull hub.c.163.com/library/mysql

[root@zhang ~]# docker images

制作镜像:

[root@zhang ~]# vim Dockerfile

from  hub.c.163.com/library/tomcat:latest

COPY jpress.war /usr/local/tomcat/webapps/

(这里的位置前面的jpress是本地wget 下来的在当前目录下的,后边的位置是网易蜂巢上对Tomcat说明的位置,不同的镜像可能位置不同,自己在镜像官网上查看,webapps/ 后面的斜杠不可以少)

Docker 实战之jpress博客部署

Docker 实战之jpress博客部署

Docker 实战之jpress博客部署

Docker 实战之jpress博客部署

 

创建自己的镜像:

[root@zhang ~]# docker build -t myjpress .   (. 容器命名为myjpress)

Sending build context to Docker daemon 94.45 MB

Sending build context to Docker daemon

Step 0 : FROM hub.c.163.com/library/tomcat:latest

---> 41414c494b22

Step 1 : COPY jpress.war /usr/local/tomcat/webapps/

---> Using cache

---> 652469107f39

Successfully built 652469107f39

[root@zhang ~]# docker images

REPOSITORY      TAG        IMAGE ID       CREATED        VIRTUAL SIZE

myjpress        latest      652469107f39     3 hours ago     313.2 MB

tomcat        latest       70b2ded797df     2 weeks ago     292.4 MB

启动容器:

[root@zhang ~]# docker run -d -p 8989:8080 myjpress

3326c1fec46caf1763a8fd69abd89269e9c4e8f5a10aa6feff647111f3312734

[root@zhang ~]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES

3326c1fec46c        myjpress            "catalina.sh run"   29 seconds ago      Up 27 seconds       0.0.0.0:8989->8080/tcp   admiring_brattain

 

[root@zhang ~]# netstat -tunlp | grep 8989

tcp        0      0 0.0.0.0:8989                0.0.0.0:*                   LISTEN      4240/docker-proxy

这时候我们自定义的容器myjpress 已经成功运行起来了,在浏览器中http://localhost:8989即可访问

(docker run -d -p 8989:8080 myjpress  前面的8989是我们随便指定一个宿主机上的端口,8080是Tomcat是容器里运行的Tomcat的端口,官网镜像上面有说明)

Docker 实战之jpress博客部署

Docker 实战之jpress博客部署

 

安装运行我们的mysql

[root@zhang ~]# docker pull mysql:5.7

[root@zhang ~]#docker run -d --name mysqlzhang -p 12340:3306 -e MYSQL_ROOT_PASSWORD=zhang123 -d mysql:5.7

[root@zhang ~]# docker ps

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                     NAMES

6ff9251a8edc        mysql:5.7           "docker-entrypoint.s   2 seconds ago       Up 2 seconds        0.0.0.0:12340->3306/tcp   mysql-zhang

3326c1fec46c        myjpress            "catalina.sh run"      14 minutes ago      Up 14 minutes       0.0.0.0:8989->8080/tcp    admiring_brattain

[root@zhang ~]#

[root@zhang ~]# docker exec -it mysql bash

Error response from daemon: Container mysql is not running

[root@zhang ~]# docker exec -it mysql-zhang bash

root@6ff9251a8edc:/# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> create database myjpress;

Query OK, 1 row affected (0.02 sec)

至此,MySQL安装成功并在容器里运行了

Docker 实战之jpress博客部署

Docker 实战之jpress博客部署

如果一直停在此画面,重启容器即可

[root@zhang ~]# docker restart 3326c1fec46c   (myjpress 的ID)

3326c1fec46c

[root@zhang ~]# docker restart 3326c1fec46c

Docker 实战之jpress博客部署

========================================

docker restart ***  //重启容器

docker ps     //显示目前在运行的容器

ifconfig   //显示IP地址

docker run -d -p 8888:8080 name   //运行某个镜像ip为8888

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=jpr mysql   //运行MYSQL,root密码为123456,创建数据库名为jpr,最后的mysql为镜像名

docker pull mysql  //下载mysql

docker images   //查看目前的镜像

docker build -t weide .    //创建镜像名字为weide

docker stop **   //关闭某运行中的容器

netstat -na|grep 8888     //查看8888端口运行

vi Dockerfile    //编写Dockerfile,按ESC后:wq保存离开vim

docker exec -it ** bash    //进入某个运行中的容器

apt-get update   //升级系统

apt-get install -y docker.io     //ubuntu安装docker

http://jpress.io/     //开源博客平台

https://dev.aliyun.com/search.html    //阿里云的docker库

 

 

 

 

  • 我的微信
  • 微信扫一扫
  • weinxin
  • 微信打赏一下咯
  • 一分钱也是爱
  • weinxin
广告也精彩
暖先生
DJI大疆 御 Mavic Air 便携可折叠4K无人机 高清航拍
VR眼镜3D虚拟现实头戴式游戏头盔rv眼睛4d手机专用ar苹果一体机
Canon/佳能 EOS 750D 套机EF-S 18-55mm IS STM
Edifier/漫步者 W830BT 无线蓝牙耳机

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: