0

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

images built successfully

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

images not exist

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

Andrew Stubbs
  • 4,322
  • 3
  • 29
  • 48

1 Answers1

0

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

hegerdes
  • 28
  • 5
  • i add script docker image ls in my .yml file, the image is exist, but in my local machine not exist. So where is the location of my images ? – Yogyakartas Jun 20 '23 at 03:36
  • When you build your image in the CI it only exists in the CI while it is running. When the job ends the runner gets wiped. When you want to share your image you have to upload it to a docker registry. Eiter Dockerhub or GH Container Registry. Then your image is either public for everyone or if it is in a private repo only accasible for you – hegerdes Jun 20 '23 at 21:30
  • great! i login in my docker hub and then upload to my docker hub, and the image is exist now. thanks!! – Yogyakartas Jun 21 '23 at 10:03