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

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

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

问题

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

  1. # 从 python 镜像开始
  2. FROM python:3.8-alpine
  3. # 将 requirements 文件复制到镜像中
  4. COPY ./requirements.txt /app/requirements.txt
  5. # 切换工作目录
  6. WORKDIR /app
  7. # 安装 requirements 文件中指定的依赖和包
  8. RUN pip3 install -r requirements.txt
  9. # 将本地文件的所有内容复制到镜像中
  10. COPY . /app
  11. EXPOSE 1201
  12. # 执行 Flask 应用
  13. CMD ["python3", "run.py"]

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

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: ["new-feature"]
  5. pull_request:
  6. branches: ["new-feature"]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: 安装 docker colima
  12. run: |
  13. brew install docker
  14. colima start
  15. - uses: actions/checkout@v3
  16. - name: 构建 Docker 镜像
  17. run: docker build --tag my_image2 .
  18. - name: 运行 docker 镜像
  19. run: docker run -d -p 1201:1201 my_image2

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

  1. Step 7/7 : CMD ["python3", "run.py"]
  2. ---> Running in f0144a0c80f6
  3. Removing intermediate container f0144a0c80f6
  4. ---> d068026c42b0
  5. Successfully built d068026c42b0
  6. 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 :

  1. # start by pulling the python image
  2. FROM python:3.8-alpine
  3. # copy the requirements file into the image
  4. COPY ./requirements.txt /app/requirements.txt
  5. # switch working directory
  6. WORKDIR /app
  7. # install the dependencies and packages in the requirements file
  8. RUN pip3 install -r requirements.txt
  9. # copy every content from the local file to the image
  10. COPY . /app
  11. EXPOSE 1201
  12. # execute the Flask app
  13. CMD ["python3", "run.py"]

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

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: [ "new-feature" ]
  5. pull_request:
  6. branches: [ "new-feature" ]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: instal docker colima
  12. run: |
  13. brew install docker
  14. colima start
  15. - uses: actions/checkout@v3
  16. - name: Build the Docker image
  17. run: docker build --tag my_image2 .
  18. - name: run docker image
  19. run: docker run -d -p 1201:1201 my_image2

and i think all working well, images built successfully :

  1. Step 7/7 : CMD ["python3", "run.py"]
  2. ---> Running in f0144a0c80f6
  3. Removing intermediate container f0144a0c80f6
  4. ---> d068026c42b0
  5. Successfully built d068026c42b0
  6. 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 文档

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: ["new-feature"]
  5. pull_request:
  6. branches: ["new-feature"]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: 检出代码
  12. uses: actions/checkout@v3
  13. - name: 设置 QEMU
  14. uses: docker/setup-qemu-action@v2
  15. - name: 设置 Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: 构建并推送
  18. uses: docker/build-push-action@v4.1.1
  19. with:
  20. push: false
  21. load: true
  22. tags: my-image
  23. - name: 运行 Docker 镜像
  24. run: |
  25. docker image ls
  26. docker run -d -p 1201:1201 my-image

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

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

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

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: ["new-feature"]
  5. pull_request:
  6. branches: ["new-feature"]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: 检出代码
  12. uses: actions/checkout@v3
  13. - name: 设置 QEMU
  14. uses: docker/setup-qemu-action@v2
  15. - name: 设置 Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: 登录到 GitHub 注册表
  18. uses: docker/login-action@v2
  19. with:
  20. registry: ghcr.io
  21. username: ${{ github.repository_owner }}
  22. password: ${{ secrets.GITHUB_TOKEN }}
  23. # 或者使用以下方式登录到 DockerHub 注册表
  24. - name: 登录到 DockerHub 注册表
  25. uses: docker/login-action@v2
  26. with:
  27. username: ${{ secrets.DOCKERHUB_USER }}
  28. password: ${{ secrets.DOCKERHUB_PW }}
  29. - name: 构建并推送
  30. uses: docker/build-push-action@v4.1.1
  31. with:
  32. push: true
  33. tags: ${{ github.repository_owner }}/my-image
  34. - name: 运行 Docker 镜像
  35. run: |
  36. docker image ls
  37. 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

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: [ "new-feature" ]
  5. pull_request:
  6. branches: [ "new-feature" ]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: Checkout code
  12. uses: actions/checkout@v3
  13. - name: Set up QEMU
  14. uses: docker/setup-qemu-action@v2
  15. - name: Set up Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: Build and push
  18. uses: docker/build-push-action@v4.1.1
  19. with:
  20. push: false
  21. load: true
  22. tags: my-image
  23. - name: run docker image
  24. run: |
  25. docker image ls
  26. 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

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: [ "new-feature" ]
  5. pull_request:
  6. branches: [ "new-feature" ]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: Checkout code
  12. uses: actions/checkout@v3
  13. - name: Set up QEMU
  14. uses: docker/setup-qemu-action@v2
  15. - name: Set up Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: Build and push
  18. uses: docker/build-push-action@v4.1.1
  19. with:
  20. push: false
  21. load: true
  22. tags: my-image
  23. - name: run docker image
  24. run: |
  25. docker image ls
  26. 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:

  1. name: Docker Image CI
  2. on:
  3. push:
  4. branches: [ "new-feature" ]
  5. pull_request:
  6. branches: [ "new-feature" ]
  7. jobs:
  8. build:
  9. runs-on: macos-latest
  10. steps:
  11. - name: Checkout code
  12. uses: actions/checkout@v3
  13. - name: Set up QEMU
  14. uses: docker/setup-qemu-action@v2
  15. - name: Set up Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: Log into registry GitHub
  18. uses: docker/login-action@v2
  19. with:
  20. registry: ghcr.io
  21. username: ${{ github.repository_owner }}
  22. password: ${{ secrets.GITHUB_TOKEN }}
  23. # Alternative
  24. - name: Log into registry DockerHub
  25. uses: docker/login-action@v2
  26. with:
  27. username: ${{ secrets.DOCKERHUB_USER }}
  28. password: ${{ secrets.DOCKERHUB_PW }}
  29. - name: Build and push
  30. uses: docker/build-push-action@v4.1.1
  31. with:
  32. push: true
  33. tags: ${{ github.repository_owner }}/my-image
  34. - name: run docker image
  35. run: |
  36. docker image ls
  37. 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:

确定