准备docker环境
[root@VM_0_45_centos ~]# yum install -y docker
[root@VM_0_45_centos ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@VM_0_45_centos ~]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@VM_0_45_centos ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-63.git94f4240.el7.centos.x86_64
Go version: go1.9.4
Git commit: 94f4240/1.13.1
Built: Fri May 18 15:44:33 2018
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-63.git94f4240.el7.centos.x86_64
Go version: go1.9.4
Git commit: 94f4240/1.13.1
Built: Fri May 18 15:44:33 2018
OS/Arch: linux/amd64
Experimental: false
可以看到docker的客户端和服务端都启动了
---------------------------------------
下载所需要的镜像 需要使用mysql和tomcat
[root@VM_0_45_centos ~]# docker pull hub.c.163.com/library/mysql:latest
Trying to pull repository hub.c.163.com/library/mysql ...
latest: Pulling from hub.c.163.com/library/mysql
42cb69312da9: Pull complete
e2cf5467c4b5: Pull complete
871ec0232f66: Pull complete
3c0ae7ec690d: Pull complete
d39b43089b70: Pull complete
aa0e7cb4b67c: Pull complete
738db9902d06: Pull complete
ae333863ac05: Pull complete
6d014992204a: Pull complete
09aeca0c9a82: Pull complete
0162083b2de0: Pull complete
Digest: sha256:b2bce1a792237ac5df78877d583f34b09ab023a77130921a6bcce67ce2d24ff0
Status: Downloaded newer image for hub.c.163.com/library/mysql:latest
[root@VM_0_45_centos ~]# docker pull hub.c.163.com/library/tomcat:latest
Trying to pull repository hub.c.163.com/library/tomcat ...
latest: Pulling from hub.c.163.com/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
查看已下载的镜像
[root@VM_0_45_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/library/tomcat latest 72d2be374029 10 months ago 292 MB
hub.c.163.com/library/mysql latest 9e64176cd8a2 14 months ago 407 MB
jpress是一个开源项目 下载jpress war包
[root@VM_0_45_centos ~]# wget https://gitee.com/fuhai/jpress/raw/alpha/wars/jpress-web-newest.war
--2018-06-30 08:42:00-- https://gitee.com/fuhai/jpress/raw/alpha/wars/jpress-web-newest.war
Resolving gitee.com (gitee.com)... 116.211.167.14
Connecting to gitee.com (gitee.com)|116.211.167.14|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘jpress-web-newest.war’
[ <=> ] 20,797,013 2.57MB/s in 8.2s
2018-06-30 08:42:09 (2.41 MB/s) - ‘jpress-web-newest.war’ saved [20797013]
[root@VM_0_45_centos ~]# ls
jpress-web-newest.war
----------------------------------------
制作docker镜像
[root@VM_0_45_centos ~]# mkdir jpress
[root@VM_0_45_centos ~]# cd jpress/
[root@VM_0_45_centos jpress]# cp ../jpress-web-newest.war ./jpress.war
[root@VM_0_45_centos jpress]# vim Dockerfile
[root@VM_0_45_centos jpress]# cat Dockerfile
FROM hub.c.163.com/library/tomcat
MAINTAINER zhaodan
COPY jpress.war /usr/local/tomcat/webapps/jpress.war
##########
FROM 表示:当前镜像依赖于tomcat镜像
MAINTAINER 表示:镜像创建者
COPY 表示:将jpress的war包复制到tomcat的webapps目录下
[root@VM_0_37_centos study]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[hub.c.163.com/library/tomcat](http://hub.c.163.com/library/tomcat) latest 72d2be374029 10 months ago 292 MB
[hub.c.163.com/library/mysql](http://hub.c.163.com/library/mysql) latest 9e64176cd8a2 13 months ago 407 MB
构建jpress镜像 使用-t参数指定镜像名为my/jpress tag为latest
[root@VM_0_45_centos jpress]# docker build -t my/jpress:latest .
Sending build context to Docker daemon 41.6 MB
Step 1/3 : FROM hub.c.163.com/library/tomcat
---> 72d2be374029
Step 2/3 : MAINTAINER zhaodan
---> Running in d21d9ca26eac
---> f3143419a182
Removing intermediate container d21d9ca26eac
Step 3/3 : COPY jpress.war /usr/local/tomcat/webapps/jpress.war
---> 01a57cf0c2e1
Removing intermediate container 5ed20c9d84e4
Successfully built 01a57cf0c2e1
[root@VM_0_45_centos jpress]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my/jpress latest 01a57cf0c2e1 About a minute ago 313 MB
hub.c.163.com/library/tomcat latest 72d2be374029 10 months ago 292 MB
hub.c.163.com/library/mysql latest 9e64176cd8a2 14 months ago 407 MB
启动docker镜像,先启动MySQL镜像,创建一个名为bolgdb的数据库,指定数据库用户以及登录密码,进行端口映射,启动数据库
[root@VM_0_45_centos jpress]# docker run --name bolgmysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=bolgdb hub.c.163.com/library/mysql
901aa0b984ca137d04d5a90a9d08b133b38b4dd709e5dc08928b002222137b3f
查看正在运行的容器
[root@VM_0_45_centos jpress]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
901aa0b984ca hub.c.163.com/library/mysql "docker-entrypoint..." 44 seconds ago Up 44 seconds 0.0.0.0:3306->3306/tcp bolgmysql
[root@VM_0_45_centos jpress]# docker run --name bolgjpress -d -p 8888:8080 my/jpress
e8acfe19e3438f6a0b15ee25570c597cd901820ee916cb4310caa00b50bb1157
[root@VM_0_45_centos jpress]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e8acfe19e343 my/jpress "catalina.sh run" 32 seconds ago Up 31 seconds 0.0.0.0:8888->8080/tcp bolgjpress
901aa0b984ca hub.c.163.com/library/mysql "docker-entrypoint..." 4 minutes ago Up 4 minutes 0.0.0.0:3306->3306/tcp bolgmysql
访问
ip + port tomcat
ip + port/jpress
image.png第一次访问需要进行安装点,击下一步进行数据库配置,将启动mysql镜像时配置的数据库名称、端口、用户名和密码对应填写
image.png image.pngimage.png
重启jpress容器,使用命令docker ps查看正在运行的容器
[root@VM_0_45_centos jpress]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e8acfe19e343 my/jpress "catalina.sh run" 13 minutes ago Up 13 minutes 0.0.0.0:8888->8080/tcp bolgjpress
901aa0b984ca hub.c.163.com/library/mysql "docker-entrypoint..." 17 minutes ago Up 17 minutes 0.0.0.0:3306->3306/tcp bolgmysql
[root@VM_0_45_centos jpress]# docker restart e8acfe19e343
e8acfe19e343
##########################
docker常用命令
docker stop 容器ID,停止容器
docker restart 容器ID,重启容器
docker start 容器ID,启动容器
docker rm 容器ID,删除容器
#########################
刷新网页
image.png登录后台
image.pngimage.png
网友评论