Tomcat容器
1.Dockerfile 版本指定7.0
from tomcat:7.0.82
COPY sources.list /etc/apt/sources.list
EXPOSE 8080
2.sources.list 源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
3.生成tomcat镜像
docker build -t pic:latest .
4.生成两个tomcat容器
#pic1 容器
docker run -v /home/eva/src1:/usr/local/tomcat/webapps --name pci1 -d -p 18080:8080 pic:latest
#pic2容器
docker run -v /home/eva/src2:/usr/local/tomcat/webapps --name pci2 -d -p 28080:8080 pic:latest
然后把项目war包,分别拷贝到src1和src2目录下
5.生成redis容器
docker run --name redis -d -p 6379:6379 redis:latest
6.查看所有正在运行的容器,停止,启动,重启
root@ubuntuserver:/home/eva# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd60175f3224 pic:latest "catalina.sh run" 9 seconds ago Up 9 seconds 0.0.0.0:28080->8080/tcp pci2
81e115052997 pic:latest "catalina.sh run" 39 seconds ago Up 39 seconds 0.0.0.0:18080->8080/tcp pci1
9ea719f54b31 redis:latest "docker-entrypoint.s…" 10 hours ago Up 14 minutes 0.0.0.0:6379->6379/tcp redis
root@ubuntuserver:/home/eva# docker stop dd6
dd6
root@ubuntuserver:/home/eva# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd60175f3224 pic:latest "catalina.sh run" 19 seconds ago Exited (143) 2 seconds ago pci2
81e115052997 pic:latest "catalina.sh run" 49 seconds ago Up 48 seconds 0.0.0.0:18080->8080/tcp pci1
9ea719f54b31 redis:latest "docker-entrypoint.s…" 10 hours ago Up 14 minutes 0.0.0.0:6379->6379/tcp redis
root@ubuntuserver:/home/eva# docker start dd6
dd6
root@ubuntuserver:/home/eva# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd60175f3224 pic:latest "catalina.sh run" 26 seconds ago Up 1 second 0.0.0.0:28080->8080/tcp pci2
81e115052997 pic:latest "catalina.sh run" 56 seconds ago Up 55 seconds 0.0.0.0:18080->8080/tcp pci1
9ea719f54b31 redis:latest "docker-entrypoint.s…" 10 hours ago Up 14 minutes 0.0.0.0:6379->6379/tcp redis
root@ubuntuserver:/home/eva# docker restart 81e11
81e11
root@ubuntuserver:/home/eva# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd60175f3224 pic:latest "catalina.sh run" 34 seconds ago Up 10 seconds 0.0.0.0:28080->8080/tcp pci2
81e115052997 pic:latest "catalina.sh run" About a minute ago Up 1 second 0.0.0.0:18080->8080/tcp pci1
9ea719f54b31 redis:latest "docker-entrypoint.s…" 10 hours ago Up 15 minutes 0.0.0.0:6379->6379/tcp redis
root@ubuntuserver:/home/eva#