docker 创建安装有tomcat的镜像,流程为:先下载镜像,用镜像启动容器,在容器中安装tomcat后保存安装了tomcat容器为新镜像。
docker 下载镜像的方式有很多,比如
sudo docker pull ubuntu:14.04
其中14.04表示ubuntu的镜像标签,如果不加标签,docker会自动下载latest标签的镜像
通过run命令用镜像启动一个容器
docker run -i -t ubuntu:14.04 /bin/bash
或使用
docker run -i -t --name test ubuntu:14.04 /bin/bash
以便在容器启动的时候指定容器的名称。
然后就可以在容器中安装tomcat 了。
具体安装方式,我这里提供一个较为完整的从镜像的下载到tomcat的安装的一篇文章
链接:http://www.21ops.com/linux/29783.html
这里有点需要注意的是,文章中用的镜像并不是ubuntu:14.04 , 如使用ubuntu:14.04可能会出现一下问题:
1、安装完ssh 并使用ssh登录 (~$ ssh root@127.0.0.1 -p 49154)的时候,会出现 Permission denied please try again.的错误
此错误网上提供的解决方案有很多。具体分三类如下:
a、修改/etc/ssh/sshd-config文件,将其中的PermitRootLogin no修改为yes,PubkeyAuthentication yes修改为no,AuthorizedKeysFile .ssh/authorized_keys前面加上#屏蔽掉,PasswordAuthentication no修改为yes
b、修改/etc/ssh/sshd-config文件,将其中的PermitRootLogin 、PubkeyAuthentication 、PasswordAuthentication 修改为yes
c、修改/etc/ssh/sshd-config文件,将其中的PermitRootLogin 、PasswordAuthentication 修改为yes
我看了我自己的这个文件,由于PubkeyAuthentication 是yes 所以我就将PermitRootLogin 、PasswordAuthentication修改成 yes便可登陆,具体可根据情况自行选择。
2、在安装
apt-get install python-software-properties
add-apt-repository ppa:webupd8team/java
第二步的时候出现:ubuntu add-apt-repository: command not found. 的错误 网上提供的解决方案是:
在安装
sudo apt-get install python-software-properties
之后 加 安装
sudo apt-get install software-properties-common
然后再进行这一步
add-apt-repository ppa:webupd8team/java
即可。