跳转至

Docker

我的第一个Dockerfile

软件

该docker包含几个我常用的软件:

  • 基于 CentOS Linux release 7.3.1611 (Core)

  • axel 下载数据用

  • git
  • zsh-syntax-highlighting.git # git 插件 谁用谁知道
  • vim
  • gcc g++ make # 额这个没有,装这个 镜像体积太大了
  • zsh
  • miniconda 64bit python=2.7

Dockerfile 内容

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
FROM centos:7.3.1611
MAINTAINER biolxy <biolxy@goodrain.com>

# Set timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN yum update -y
RUN yum install curl vim wget \
    gettext gettext-devel autoconf automake libtool openssl \
    openssl-devel zsh -y
RUN yum install bzip2 -y

# yum clean
RUN rm -rf /var/lib/apt/lists/*

# mkdir app
RUN mkdir -p /app
# Set WORKDIR
WORKDIR /app

# install axel
RUN git clone https://github.com/axel-download-accelerator/axel.git
RUN cd axel && autoreconf -i && ./configure && make && make install

# install zsh
RUN chsh -s `which zsh` root
COPY install.sh /app/install.sh
RUN chmod +x /app/install.sh
COPY oh-my-zsh /app/oh-my-zsh
RUN /app/install.sh
# install zsh-syntax-highlighting
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# add plugins
RUN echo "plugins=(plugins zsh-syntax-highlighting)" >> ~/.zshrc
RUN echo "source \$ZSH/oh-my-zsh.sh" >> ~/.zshrc
# install conda
COPY Miniconda2-latest-Linux-x86_64.sh /app/Miniconda2-latest-Linux-x86_64.sh
RUN /bin/bash /app/Miniconda2-latest-Linux-x86_64.sh -b -p /opt/conda && \
    rm /app/Miniconda2-latest-Linux-x86_64.sh && \
    echo "export PATH=/opt/conda/bin:$PATH" >> ~/.zshrc
RUN echo "export PATH=/opt/conda/bin:$PATH" >> ~/.bashrc
RUN source ~/.bashrc && conda clean --all -y

创建docker image

Text Only
1
docker build -t devtools:v3.0 .

参考

  • https://www.oschina.net/question/584116_2209819

基于已有的image创建dockerimages

1、 创建docker images 有两种方法

  • 运行一个容器,在运行容器的基础上安装软件,部署服务,然后导出为新的image
  • 通过编写dockerfile文件来创建新的image

配合docker 私有仓库,可以用来部署生产环境

2、 缘起

本文记录了在一个已近存在的docker image,安装软件,并保存为新image的过程。

首先通过:

Bash
1
docker images

找到我们事先下载好得

Bash
1
docker images

docker.io/hiono/texlive

3、 运行 docker 镜像:

Bash
1
docker run -it docker.io/hiono/texlive 

以下操作都发生在运行的该docker image中

3.1、 下载 anaconda
Bash
1
wget  https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
3.2、 安装 anaconda
Bash
1
2
3
4
5
6
Anaconda3-5.2.0-Linux-x86_64.sh: 350: Anaconda3-5.2.0-Linux-x86_64.sh: bunzip2: not found
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
root@890b8b636b88:~# yum install -y bzip2
-su: yum: command not found
root@890b8b636b88:~# apt-get install -y bzip2
3.3、 安装依赖环境以及treeomics软件

按照 https://github.com/johannesreiter/treeomics 要求创建环境,安装相应得依赖环境

Bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
conda create  -n treeomics  python=3.4 NumPy SciPy networkx seaborn pandas matplotlib=1.5
apt-get update 
apt-get install git
git clone https://github.com/johannesreiter/treeomics.git
apt-get install wkhtmltopdf
pip install pdfkit
conda install perl=5.26.2
conda update -n base conda
apt-get install circos
apt-get install cpanminus
cpanm SVG
pip install varcode
pip install pyensembl
Bash
1
git clone https://github.com/johannesreiter/treeomics
3.4、 安装 cplex
Bash
1
2
3
4
./cplex_studio126.linux-x86-64.bin
2
cd /opt/ibm/ILOG/CPLEX_Studio1261/cplex/python/3.4/x86-64_linux
python setup.py install

4、 测试

Bash
1
2
cd /root/treeomics/src
python treeomics -h

出现帮助信息,表明依赖安装完毕……

5、 docker 封装

新开一个shell 窗口,docker ps 获得我们docker 容器的id 890b8b636b88

exit 退出正在运行的 docker 容器 后

Bash
1
2
$ docker commit -m "a docker image for treeomics" -a "biolxy<biolxy@aliyun.com>" 890b8b636b88 ubuntu_treeomics
sha256:0bd8695dd6d647b249d7469eac397595ddbe40e7391415805d59f05d7d375e3d

mark

可以查看到我们创建的镜像了,OK

5.1、 使用:
Bash
1
docker run -it -v `pwd`:`pwd` -w `pwd`  ubuntu_treeomics

6、 参考

  • https://blog.csdn.net/leo15561050003/article/details/71274718?locationNum=14&fps=1
  • https://www.cnblogs.com/mthoutai/p/6812871.html