FROM 基礎鏡像(使用docker search 選擇須要的基礎鏡像)python
COPY
複製的時候但願能保留本來的目錄git
COPY ./ /admin/ RUN ls -la /admin/*
RUN 運行命令,每RUN即新增一層github
WORKDIR 設置工做目錄,進入容器後的當前目錄sql
ENV 設置環境變量docker
安裝基礎經常使用命令vim
RUN yum update -y && yum -y install vim wget curl unzip zip gcc make lsof zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libffi-devel libpcap-devel xz-devel git make libaio libnsl
配置單獨python環境(系統自帶python環境通常爲python2)centos
RUN mkdir ~/.pyenv && git clone git://github.com/yyuu/pyenv.git ~/.pyenv RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc RUN echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc RUN echo 'eval "$(pyenv init -)"' >> ~/.bashrc RUN source ~/.bashrc RUN /root/.pyenv/bin/pyenv install --list RUN /root/.pyenv/bin/pyenv install 3.6.8 -v && /root/.pyenv/bin/pyenv global 3.6.8 RUN /root/.pyenv/shims/pip install --upgrade pip
ENTRYPOINT 和 CMD 命令區別bash
ENTRYPOINT 和 CMD 命令告知後臺程序啓動時候須要執行的命令,當docker run 的時候加了參數,cmd 裏面的默認命令或者參數會被覆蓋 因此ENTRYPOINT裏面放不變的必定要執行的命令,可變參數能夠放在CMD命令 例如: ENTRYPOINT ["/root/.pyenv/shims/python3.6", "/home/admin/manage.py", "runserver", "&"]