Docker构建成功,但在docker images中未显示构建的镜像。

huangapple go评论135阅读模式
英文:

Docker built successfully but no built image show up in the docker images

问题

我创建了一个 Flask 应用并使用 Docker 部署它,我在 Mac 上手动部署并成功了,以下是我的 Dockerfile 脚本:

# 从 python 镜像开始
FROM python:3.8-alpine

# 将 requirements 文件复制到镜像中
COPY ./requirements.txt /app/requirements.txt

# 切换工作目录
WORKDIR /app

# 安装 requirements 文件中指定的依赖和包
RUN pip3 install -r requirements.txt

# 将本地文件的所有内容复制到镜像中
COPY . /app

EXPOSE 1201

# 执行 Flask 应用
CMD ["python3", "run.py"]

然后我尝试使用 GitHub Actions 进行自动部署,以下是我的 YML 脚本:

name: Docker Image CI

on:
  push:
    branches: ["new-feature"]
  pull_request:
    branches: ["new-feature"]
   

jobs:

  build:
    runs-on: macos-latest

    steps:

    - name: 安装 docker colima
      run:  |
          brew install docker
          colima start          

    - uses: actions/checkout@v3
    - name: 构建 Docker 镜像
      run: docker build --tag my_image2 .
    
    - name: 运行 docker 镜像
      run: docker run -d -p 1201:1201 my_image2

我认为一切都正常工作,镜像已成功构建:

Step 7/7 : CMD ["python3", "run.py"]
 ---> Running in f0144a0c80f6
Removing intermediate container f0144a0c80f6
 ---> d068026c42b0
Successfully built d068026c42b0
Successfully tagged my_image2:latest

然后我检查我的镜像不存在,无论在 Docker 还是在 colima 中。

所以问题是什么,你们能给我一个解决方案吗?谢谢!

Docker构建成功,但在docker images中未显示构建的镜像。

Docker构建成功,但在docker images中未显示构建的镜像。

英文:

I was create flask-app and deploy it using docker, i deploy manually in mac and success, this is my Dockerfile script :

# start by pulling the python image
FROM python:3.8-alpine

# copy the requirements file into the image
COPY ./requirements.txt /app/requirements.txt

# switch working directory
WORKDIR /app

# install the dependencies and packages in the requirements file
RUN pip3 install -r requirements.txt

# copy every content from the local file to the image
COPY . /app

EXPOSE 1201

# execute the Flask app
CMD ["python3", "run.py"]

and i try to automatic deploy using github actions, and it is my YML script :

name: Docker Image CI

on:
  push:
    branches: [ "new-feature" ]
  pull_request:
    branches: [ "new-feature" ]
   

jobs:

  build:
    runs-on: macos-latest

    steps:

    - name: instal docker colima
      run:  |
          brew install docker
          colima start

    - uses: actions/checkout@v3
    - name: Build the Docker image
      run: docker build --tag my_image2 .
    
    - name: run docker image
      run: docker run -d -p 1201:1201 my_image2

and i think all working well, images built successfully :

Step 7/7 : CMD ["python3", "run.py"]
 ---> Running in f0144a0c80f6
Removing intermediate container f0144a0c80f6
 ---> d068026c42b0
Successfully built d068026c42b0
Successfully tagged my_image2:latest

Docker构建成功,但在docker images中未显示构建的镜像。

and then i check my image not exist, in docker even in colima

Docker构建成功,但在docker images中未显示构建的镜像。

So what the problem, and you guys can give me a solution ? thank you

答案1

得分: 0

Docker 最近将构建后端更改为默认使用 buildx,这可能会导致一些问题,具体取决于您使用的 Docker 版本以及安装方式。为了避免依赖于平台的代码,可以使用预定义的操作:

请查看官方 GH-Action Docker Build 文档

name: Docker Image CI

on:
  push:
    branches: ["new-feature"]
  pull_request:
    branches: ["new-feature"]

jobs:
  build:
    runs-on: macos-latest
    steps:
      - name: 检出代码
        uses: actions/checkout@v3

      - name: 设置 QEMU
        uses: docker/setup-qemu-action@v2

      - name: 设置 Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: 构建并推送
        uses: docker/build-push-action@v4.1.1
        with:
          push: false
          load: true
          tags: my-image

      - name: 运行 Docker 镜像
        run: |
          docker image ls
          docker run -d -p 1201:1201 my-image          

当您想在其他计算机上使用该镜像时,您需要将其上传到 DockerHub 或 GitHub 容器注册表之类的注册表:

Docker 最近将构建后端更改为默认使用 buildx,这可能会导致一些问题,具体取决于您使用的 Docker 版本以及安装方式。为了避免依赖于平台的代码,可以使用预定义的操作:

请查看官方 GH-Action Docker Build 文档

name: Docker Image CI

on:
  push:
    branches: ["new-feature"]
  pull_request:
    branches: ["new-feature"]

jobs:
  build:
    runs-on: macos-latest
    steps:
      - name: 检出代码
        uses: actions/checkout@v3

      - name: 设置 QEMU
        uses: docker/setup-qemu-action@v2

      - name: 设置 Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: 登录到 GitHub 注册表
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # 或者使用以下方式登录到 DockerHub 注册表
      - name: 登录到 DockerHub 注册表
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_PW }}

      - name: 构建并推送
        uses: docker/build-push-action@v4.1.1
        with:
          push: true
          tags: ${{ github.repository_owner }}/my-image

      - name: 运行 Docker 镜像
        run: |
          docker image ls
          docker run -d -p 1201:1201 my-image          
英文:

Docker recently changed their build backend to use buildx as default. It may cause some issues depending on the version of docker you use and how you install it. To avoid plattform dependent code use predefined actions:

See the official GH-Action Docker Build Docs

name: Docker Image CI

on:
  push:
    branches: [ "new-feature" ]
  pull_request:
    branches: [ "new-feature" ]
   
jobs:
  build:
    runs-on: macos-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Build and push
        uses: docker/build-push-action@v4.1.1
        with:
          push: false
          load: true
          tags: my-image

      - name: run docker image
        run: |
          docker image ls
          docker run -d -p 1201:1201 my-image          

When you want to use the image on other machines you have to upload it to a registry like DockerHub or GitHub Container Registry:

Docker recently changed their build backend to use buildx as default. It may cause some issues depending on the version of docker you use and how you install it. To avoid plattform dependent code use predefined actions:

See the official GH-Action Docker Build Docs

name: Docker Image CI

on:
  push:
    branches: [ "new-feature" ]
  pull_request:
    branches: [ "new-feature" ]
   
jobs:
  build:
    runs-on: macos-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Build and push
        uses: docker/build-push-action@v4.1.1
        with:
          push: false
          load: true
          tags: my-image

      - name: run docker image
        run: |
          docker image ls
          docker run -d -p 1201:1201 my-image          

When you want to use the image on other machines you have to upload it to a registry like DockerHub or GitHub Container Registry:

name: Docker Image CI

on:
  push:
    branches: [ "new-feature" ]
  pull_request:
    branches: [ "new-feature" ]
   
jobs:
  build:
    runs-on: macos-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Log into registry GitHub
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # Alternative
      - name: Log into registry DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_PW }}

      - name: Build and push
        uses: docker/build-push-action@v4.1.1
        with:
          push: true
          tags: ${{ github.repository_owner }}/my-image

      - name: run docker image
        run: |
          docker image ls
          docker run -d -p 1201:1201 my-image          

huangapple
  • 本文由 发表于 2023年6月19日 18:02:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定