Docker - 制作Docker镜像
从GitHub上构建Docker镜像的步骤包括:在本地创建一个Dockerfile、在本地构建镜像、推送到Docker Hub、在GitHub Actions中配置CI/CD流水线,GitHub Actions在每次代码提交时自动构建和推送Docker镜像。
1.镜像:类似于模版,在没有添加实例化前不能使用。
2.容器:镜像实例化。
3.docker:放容器的一个载体
Docker 镜像由只读层组成,每个层代表一条 Dockerfile 指令。这些层是堆叠在一起的,每一层都是与前一层的变化的增量。
# syntax=docker/dockerfile:1
FROM ubuntu:22.04
COPY . /app
RUN make /app
CMD python /app/app.py
在上面的示例中,每条指令创建一层:
FROM从 Docker 镜像创建一个层ubuntu:22.04。
COPY从 Docker 客户端的当前目录添加文件。
RUN使用 构建您的应用程序make。
CMD指定要在容器内运行的命令
Step 1: Create a Dockerfile
# Use a lightweight base image
FROM ubuntu:22.04
# Install dependencies
RUN apt-get update && apt-get install -y \
git \
build-essential \
python3 \
python3-pip \
network-manager
# Clone Matter SDK
RUN git clone --depth 1 https://github.com/project-chip/connectedhomeip.git
# Build Matter
WORKDIR /connectedhomeip
RUN source scripts/activate.sh && \
scripts/build/gn_gen.sh --args='chip_transport_wifi=false chip_transport_ethernet=true' && \
ninja -C out
# Expose ports for Matter over Ethernet (e.g., UDP/5540)
EXPOSE 5540/udp
CMD ["/connectedhomeip/scripts/start-controller.sh"]
在GitHub Actions中配置CI/CD流水线
GitHub Actions允许在每次代码提交时自动构建和推送Docker镜像。以下是配置CI/CD流水线的步骤:
在项目根目录创建一个.github/workflows目录。
在该目录下创建一个YAML文件,例如docker-image.yml,并添加以下内容:
1.拉取下载镜像文件
git clone
2.下载后的镜像文件一般有dockerfile,.dockerfie,库源码包··
3.阅读readme,一般里面有相应的build方法
4.docker build -t [镜像名]:[版本号]
5.
查看镜像id及镜像名:
docker image ls
结果:
REPOSITORY TAG IMAGE ID CREATED SIZE
aaaimage v1.0 c7f83bf645b3 4 hours ago 5.02GB//docker
dorowu/ubuntu
useful links
https://docker.github.net.cn/develop/develop-images/dockerfile_best-practices/
用github的dockerfile自动生成docker镜像
https://www.cnblogs.com/jackadam/p/9155296.html