其他分享
首页 > 其他分享> > Dockerfile详解

Dockerfile详解

作者:互联网

Dockerfile详解

一、Dockerfile

Dockerfile 是一个用来构建镜像的文本文件,文本内容包含了一条条构建镜像所需的指令和说明。

二、基本参数说明

1、FROM

FROM python:alpine

2、LABEL

3、COPY

COPY . /app

4、ADD

ADD <https://github.com/docker-library/python/raw/master/update.sh> .

5、WORKDIR

WORKDIR /app

6、RUN

RUN pip install -r requirements.txt

7、ENV

ENV username=Desire\\
    password=123456

8、VOLUME

LABEL maintaier="Desire <desireyang.qq.com>"
LABEL description="define Dockerfile Demo"

9、EXPOSE

EXPOSE 8000

10、CMD

CMD ["python", "fun.py"]
# CMD ["/bin/ls","/","/etc"]
# CMD python fun.py

11、ENTRYPOINT

ENTRYPOINT ["python", "fun.py"]
ENTRYPOINT ["cat", "fun.py"]
CMD ["etc/passwd"]
# 可以指定shell脚本
ENTRYPOINT ["/bin/sh","docker-entrypoint.sh"]

12、ARG

# 只在 FROM 中生效
ARG DOCKER_USERNAME=library

FROM ${DOCKER_USERNAME}/alpine

# 要想在 FROM 之后使用,必须再次指定
ARG DOCKER_USERNAME=library

RUN set -x ; echo ${DOCKER_USERNAME}

13、USER

USER root

三、通过Dockerfile文件构建镜像

docker build -t 镜像名:tag -f 指定Dockerfile文件路径 .

四、完整的Dockerfile文件

FROM python:alpine

LABEL maintaier="Desire <desireyang.qq.com>"
LABEL description="define Dockerfile Demo"

COPY . /app

# ADD <https://github.com/docker-library/python/raw/master/update.sh> .

WORKDIR /app

RUN pip install -r requirements.txt

ENV username=Desire\\
    password=123456

VOLUME /app

# EXPOSE 8000

CMD ["python", "fun.py"]
# CMD ["/bin/ls","/","/etc"]
# CMD python fun.py

# ENTRYPOINT ["python", "fun.py"]
# ENTRYPOINT ["cat", "fun.py"]
# CMD ["etc/passwd"]
# 可以指定shell脚本
# ENTRYPOINT ["/bin/sh","docker-entrypoint.sh"]

标签:容器,CMD,指定,详解,ENTRYPOINT,镜像,Dockerfile
来源: https://blog.csdn.net/RoninYang/article/details/120813852