首页 > 代码库 > Dockerfile

Dockerfile

运行一个ubuntu容器

docker run -i -t ubuntu /bin/bash

备份apt源

cp /etc/apt/sources.list /etc/apt/sources.list.bak

修改apt源

vi /etc/apt/sources.list

替换所有源为sohu源

deb http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiversedeb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiversedeb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiversedeb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiversedeb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiversedeb-src http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiversedeb-src http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiversedeb-src http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiversedeb-src http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiversedeb-src http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse

或网易源

deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

修改保存后退出运行的容器

exit

查看最后一个运行的容器

docker ps -l

提交本次修改的镜像为 ubuntu/sohu

docker commit 698 ubuntu/sohu

使用修改后源的镜像做Dockerfile

# VERSION 0.0.1FROM ubuntu/sohuMAINTAINER myemail "myemail@gmail.com"RUN apt-get updateRUN apt-get install -y openssh-serverRUN mkdir -p /var/run/sshdRUN echo "root:123456" | chpasswd RUN apt-get install python-software-propertiesRUN add-apt-repository ppa:webupd8team/javaRUN apt-get updateRUN apt-get install -y vim wget curl oracle-java7-installer tomcat7RUN update-alternatives --display javaRUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle">> /etc/environmentRUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle">> /etc/default/tomcat7EXPOSE 22EXPOSE 8080ENTRYPOINT service tomcat7 start && /usr/sbin/sshd -D

 

需要注意:

  1. ENTRYPOINT,表示镜像在初始化时需要执行的命令,不可被重写覆盖,需谨记
  2. CMD,表示镜像运行默认参数,可被重写覆盖
  3. ENTRYPOINT/CMD都只能在文件中存在一次,并且最后一个生效 多个存在,只有最后一个生效,其它无效!
  4. 需要初始化运行多个命令,彼此之间可以使用 && 隔开,但最后一个须要为无限运行的命令,需切记!

启动新建的容器

 docker run -d -p 22 -p 8080:8080 saint/tomcat7

 

 

http://www.blogjava.net/yongboy/archive/2013/12/16/407643.html

Dockerfile 命令解释

http://blog.tankywoo.com/docker/2014/05/08/docker-2-dockerfile.html

查找apt软件

apt-cache search tomcat

 

Dockerfile