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
and then i check my image not exist, in docker even in colima
So what the problem, and you guys can give me a solution ? thank you
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