title |
---|
Dockerfile |
Dockerfile 是由命令和参数构成的脚本,用于生成镜像.
-
FROM
# 加载 alpine tag 版本的 python Image # alpine 版本下可以使用 apk 包管理工具 # As 作为别名供其他命令使用 python:alpine AS base
-
WORKDIR
# 定位到 容器应用根目录 /app 下 /app
-
COPY
# 复制当前目录下 文件 黏贴到容器的根目录下 COPY ./requirements.txt . # 复制当前目录下 所有文件 黏贴到容器的根目录下,最好移动到底部 COPY . . # 放到项目里的跟目录下 -> 更改下载源 COPY ./pip.conf /etc/pip.conf
-
ADD
# ADD [source directory] [destination directory] ADD /app /home/androllen
-
RUN
# 可指定国内源下载依赖 -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir # RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements.txt RUN pip install -r requirements.txt # 编译 /app下的文件 RUN make /app # 创建/usr/local/tomcat目录 RUN mkdir /usr/local/tomcat #安装wget命令 RUN apk add wget # wget tomcat.tar.gz 到 /usr/local/tomcat 目录 RUN wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.104/bin/apache-tomcat-7.0.104.tar.gz
-
CMD
If you list more than one CMD then only the last CMD will take effect
- CMD ["executable","param1","param2"] (exec form, this is the preferred form)
- CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
- CMD command param1 param2 (shell form)
# $echo $HOME CMD ["echo", "$HOME"] # $sh -c "echo $HOME" CMD [ "sh", "-c", "echo $HOME" ]
COPY ./pip.conf /etc/pip.conf
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
# install psycopg2 dependencies
# RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
RUN apk update
RUN apk add postgresql-dev gcc python3-dev musl-dev
Best practices for writing Dockerfiles
Dockerfile for python tag