码迷,mamicode.com
首页 > 其他好文 > 详细

Dockerfile

时间:2014-09-23 02:37:53      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   使用   java   ar   

运行一个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 multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse

或网易源

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

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

exit

查看最后一个运行的容器

docker ps -l

bubuko.com,布布扣

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

docker commit 698 ubuntu/sohu

使用修改后源的镜像做Dockerfile

# VERSION 0.0.1

FROM ubuntu/sohu

MAINTAINER myemail "myemail@gmail.com"

RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd

RUN echo "root:123456" | chpasswd 

RUN apt-get install python-software-properties
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update
RUN apt-get install -y vim wget curl oracle-java7-installer tomcat7

RUN update-alternatives --display java
RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle">> /etc/environment
RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle">> /etc/default/tomcat7

EXPOSE 22

EXPOSE 8080

ENTRYPOINT 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

标签:style   blog   http   color   io   os   使用   java   ar   

原文地址:http://www.cnblogs.com/saintaxl/p/3987432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!