Ubuntu Docker部署war项目
Ubuntu Docker部署war项目
1、安装docker
官方的docker安装方式已经失效。安装最新的docker采用以下命令。
添加docker源:
注意:不同的ubuntu版本源有所差异,根据实际情况添加不同的源
其他版本系统源地址如下:
Ubuntu version |
Repository |
Precise 12.04 (LTS) |
deb https://apt.dockerproject.org/repo ubuntu-precise main |
Trusty 14.04 (LTS) |
deb https://apt.dockerproject.org/repo ubuntu-trusty main |
Wily 15.10 |
deb https://apt.dockerproject.org/repo ubuntu-wily main |
Xenial 16.04 (LTS) |
deb https://apt.dockerproject.org/repo ubuntu-xenial main |
查看ubuntu版本的命令如下:cat/etc/issue
更新源:apt-get update
安装docker:apt-getinstall docker-engine
软连接:sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
查看是否安装成功:docker –v
2、编写 Dockerfile
注意:将生成的war包命名为ROOT.war,tomcat的server.xml文件放到跟Dockerfile同一目录下,server.xml的作用是修改tomcat默认的端口,如果采用默认端口,不需要该文件。
3、编译镜像
Dokcerfile采用了官方的tomcat镜像源,下载慢,所以这里配置一下阿里云docker加速器。
{
"registry-mirrors":["{加速器地址}]"]
}
编译镜像
docker build-t tomcat/yucai .
查看镜像:dockerimages
启动镜像:
docker run -p9010:9010 -t --network=host tomcat/yucai
查看容器:
docker ps -a
查看log:
docker logs –f{容器名称}