🌐
Docker
docs.docker.com › manuals › docker build › ci › github actions
GitHub Actions | Docker Docs
Docker maintains a set of official GitHub Actions for building Docker images.
🌐
GitHub
github.com › docker › build-push-action
GitHub - docker/build-push-action: GitHub Action to build and push Docker images with Buildx · GitHub
March 11, 2026 - GitHub Action to build and push Docker images with Buildx with full support of the features provided by Moby BuildKit builder toolkit. This includes multi-platform build, secrets, remote cache, etc.
Starred by 5.2K users
Forked by 709 users
Languages   TypeScript 87.7% | Dockerfile 8.0% | JavaScript 2.0% | HCL 1.9% | Go 0.4%
🌐
Docker
docs.docker.com › guides › react.js › automate your builds with github actions
Automate your builds with GitHub Actions | Docker Docs
Go to your repository on GitHub and select the Actions tab in the top menu. Select Set up a workflow yourself when prompted. This opens an inline editor to create a new workflow file.
🌐
GitHub
docs.github.com › actions › sharing-automations › creating-actions › creating-a-docker-container-action
Creating a Docker container action - GitHub Docs
To pass inputs to the Docker container, you should declare the input using inputs and pass the input in the args keyword. Everything you include in args is passed to the container, but for better discoverability for users of your action, we ...
🌐
Medium
medium.com › rewrite-tech › how-to-create-custom-ci-cd-with-github-and-docker-495e8ff87c7e
How To Create Custom CI/CD With Github and Docker | by Eugenio Di Tullio | REWRITE TECH by Diconium | Medium
December 4, 2024 - This action is publicly available on GitHub at https://github.com/actions/checkout/tree/v2 · name: Similarly as before, but in this case the name of a step of our pipeline. This section will contain attributes such as ... env: environment variables to be used in the environment where the script is going to run (with the run command). This is the most cryptic part of the configuration and it’s the one that contains all the magic that allows GitHub to “talk” with our remote docker instance using SSH.
🌐
GitHub
docs.github.com › en › actions › reference › workflows-and-actions › dockerfile-support
Dockerfile support for GitHub Actions - GitHub Docs
It's recommended to not use the WORKDIR instruction in your Dockerfile. Before the action executes, GitHub will mount the GITHUB_WORKSPACE directory on top of anything that was at that location in the Docker image and set GITHUB_WORKSPACE as the working directory.
🌐
Datawookie
datawookie.dev › blog › 2024-04-21-dind-in-github-actions
Docker-in-Docker with GitHub Actions – datawookie
April 21, 2024 - name: Test Docker on GitHub Actions on: pull_request: push: branches: - master jobs: push_container: runs-on: ubuntu-latest services: docker: image: docker:dind options: --privileged --shm-size=2g volumes: - /var/run/docker.sock:/var/run/docker.sock:ro container: image: ubuntu:latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install Docker run: | apt-get update apt-get install -y docker.io - name: Test Docker run: | docker version docker info
🌐
GitHub
github.com › actions › hello-world-docker-action
GitHub - actions/hello-world-docker-action: A template to demonstrate how to build a Docker action. · GitHub
name: Example Workflow on: workflow_dispatch: inputs: who-to-greet: description: Who to greet in the log required: true default: 'World' type: string jobs: say-hello: name: Say Hello runs-on: ubuntu-latest steps: # Change @main to a specific commit SHA or version tag, e.g.: # actions/hello-world-docker-action@e76147da8e5c81eaf017dede5645551d4b94427b # actions/hello-world-docker-action@v1.2.3 - name: Print to Log id: print-to-log uses: actions/hello-world-docker-action@main with: who-to-greet: ${{ inputs.who-to-greet }}
Starred by 178 users
Forked by 190 users
Languages   Dockerfile 62.6% | Shell 37.4%
Find elsewhere
🌐
GitHub
github.com › nektos › act
GitHub - nektos/act: Run your GitHub Actions locally 🚀
When you run act it reads in your GitHub Actions from .github/workflows/ and determines the set of actions that need to be run. It uses the Docker API to either pull or build the necessary images, as defined in your workflow files and finally determines the execution path based on the dependencies that were defined.
Starred by 69.8K users
Forked by 1.9K users
Languages   Go 81.5% | JavaScript 17.1% | Shell 1.1% | Makefile 0.3%
🌐
Docker
docs.docker.com › manuals › docker build › ci › github actions › multi-platform image
Multi-platform image with GitHub Actions
The following example workflow enables the containerd image store, builds a multi-platform image, and loads the results into the GitHub runner's local image store. name: ci on: push: jobs: docker: runs-on: ubuntu-latest steps: - name: Set up Docker uses: docker/setup-docker-action@v5 with: daemon-config: | { "debug": true, "features": { "containerd-snapshotter": true } } - name: Login to Docker Hub uses: docker/login-action@v4 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set up QEMU uses: docker/setup-qemu-action@v4 - name: Build and push uses: docker/build-push-action@v7 with: platforms: linux/amd64,linux/arm64 load: true tags: user/app:latest
🌐
Docker
docs.docker.com › guides › github actions and docker
GitHub Actions and Docker | Docker Docs
Next, under Variables, create a ... Actions workflows define a series of steps to automate tasks, such as building and pushing Docker images, in response to triggers like commits or pull requests....
Top answer
1 of 1
1

Yes this is certainly possible, you can run arbitrary code within a github action. However, I would advise you to instead publish your docker image on a repository and simply use it via container: docker://<url_of_your_image>

That being said, if you need to follow the steps you outlined:

I'll condense your last steps into a build-my-application as they will vary depending on how you build/deploy your app.

git clone my dockerfile from a 3rd party git url

Assuming the repo you are accessing is publicly available, or the git user running the action has access. If not you may need to replace the use of curl with a more complex git command.

name: Build and Run Docker Image

on:
  push:
    branches:
      - main

jobs:
  build-and-run:
    runs-on: ubuntu-latest
    
    steps:
    - name: Download Dockerfile from external repository
      run: |
        curl -LJO https://raw.githubusercontent.com/external/repo/main/path/to/dockerfile
      working-directory: path/to/your/dockerfile/directory

    - name: Build Docker image
      run: |
        docker build -t my-docker-image .
     
    - name: Run Docker container
      run: |
        docker run -d --name my-container my-docker-image
    
    - name: Run arbitrary code inside the container
      run: |
        docker exec my-container ./build-my-application
   

Note: If have more needs other than just building the container and running a script, or you need to anchor to a particular version of docker you should specify a container for the job itself to run in i.e. a container to build your container inside.

e.g.

jobs:
  build-and-run:
    runs-on: ubuntu-latest
    container:
      image: docker:20.10.9  # Specify the Docker version you need
🌐
GitHub
github.com › docker › setup-compose-action
GitHub - docker/setup-compose-action: GitHub Action to set up Docker Compose · GitHub
GitHub Action to set up Docker Compose. Contribute to docker/setup-compose-action development by creating an account on GitHub.
Starred by 39 users
Forked by 5 users
Languages   TypeScript 47.8% | Dockerfile 26.3% | JavaScript 13.1% | HCL 12.8%
🌐
GitHub
github.com › marketplace › actions › build-and-push-docker-images
Build and push Docker images · Actions · GitHub Marketplace · GitHub
GitHub Action to build and push Docker images with Buildx with full support of the features provided by Moby BuildKit builder toolkit. This includes multi-platform build, secrets, remote cache, etc.
🌐
GitHub
docs.github.com › actions › using-jobs › running-jobs-in-a-container
Running jobs in a container - GitHub Docs
If you do not set a container, all steps will run directly on the host specified by runs-on unless a step refers to an action configured to run in a container. ... The default shell for run steps inside a container is sh instead of bash. This can be overridden with jobs.<job_id>.defaults.run or jobs.<job_id>.steps[*].shell. ... name: CI on: push: branches: [ main ] jobs: container-test-job: runs-on: ubuntu-latest container: image: node:18 env: NODE_ENV: development ports: - 80 volumes: - my_docker_volume:/volume_mount options: --cpus 1 steps: - name: Check for dockerenv file run: (ls /.dockerenv && echo Found dockerenv) || (echo No dockerenv)
Top answer
1 of 2
126

GitHub actions provision a virtual machine - as you noted, either Ubuntu, Windows or macOS - and run your workflow inside of that. You can then use that virtual machine to run a workflow inside a container.

Use the container specifier to run a step inside a container. Be sure to specify runs-on as the appropriate host environment for your container (ubuntu-latest for Linux containers, windows-latest for Windows containers). For example:

jobs:
  vm:
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo This job does not specify a container.
          echo It runs directly on the virtual machine.
        name: Run on VM
  container:
    runs-on: ubuntu-latest
    container: node:10.16-jessie
    steps:
      - run: |
          echo This job does specify a container.
          echo It runs in the container instead of the VM.
        name: Run in container
2 of 2
59

A job (as part of a workflow) runs inside a virtual machine. You choose one of the environments provided by them (e.g. ubuntu-latest or windows-2019).

A job consists of one or more steps. A step may be a simple shell command, using run. But it may also be an action, using uses

name: CI

on: [push]

jobs:
  myjob:
    runs-on: ubuntu-18.04 # linux required if you want to use docker
    steps:
    # Those steps are executed directly on the VM
    - run: ls /
    - run: echo $HOME
    - name: Add a file
      run: touch $HOME/stuff.txt
    # Those steps are actions, which may run inside a container
    - uses: actions/checkout@v1
    - uses: ./.github/actions/my-action
    - uses: docker://continuumio/anaconda3:2019.07
  • run: <COMMAND> executes the command with the shell of the OS
  • uses: actions/checkout@v1 runs the action from the user / organization actions in the repository checkout (https://github.com/actions/checkout), major release 1
  • uses: ./.github/actions/my-action runs the action which is defined in your own repository under this path
  • uses: docker://continuumio/anaconda3:2019.07 runs the anaconda3 image from user / organization continuumio, version 2019.07, from the Docker Hub (https://hub.docker.com/r/continuumio/anaconda3)

Keep in mind that you need to select a linux distribution as the environment if you want to use Docker.

Take a look at the documentation for uses and run for further details.

It should also be noted that there is a container option, allowing you to run any steps that would usually run on the host to be runned inside a container: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idcontainer

🌐
Earthly
earthly.dev › blog › github-actions-and-docker
Using GitHub Actions to Run, Test, Build, and Deploy Docker Containers - Earthly Blog
July 11, 2023 - GitHub Actions is a flexible tool that enables developers to automate a variety of processes, including developing, testing, and deploying, right from their GitHub repositories. The automation of Docker containers is no exception since GitHub ...
🌐
GitHub
github.com › docker › setup-buildx-action
GitHub - docker/setup-buildx-action: GitHub Action to set up Docker Buildx · GitHub
GitHub Action to set up Docker Buildx. Contribute to docker/setup-buildx-action development by creating an account on GitHub.
Starred by 1.3K users
Forked by 237 users
Languages   TypeScript 87.3% | Dockerfile 6.4% | JavaScript 3.2% | HCL 3.1%
🌐
Medium
medium.com › @kicsipixel › using-github-actions-to-automatically-build-docker-images-65a038b8ce56
Using GitHub Actions to automatically build Docker images | by Szabolcs Toth | Medium
May 11, 2024 - The steps: 1. Create a repository on GitHub 2. Create a repository on dockerhub 3. Create an Access Token on dockerhub 4. Add the Access Token to the GitHub repository 5. Create the “Action” 6.
🌐
Medium
medium.com › @code0987 › creating-a-github-action-for-a-docker-image-b00871844bdc
Creating a GitHub Action for a Docker Image | by code0987 | Medium
May 28, 2023 - name: 'Hello World' description: 'Greet someone and record the time'runs: using: 'docker' image: 'Dockerfile' name: Android CI on: [push] jobs: android-ci: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: "Android CI Github Action" uses: code0987/android-ci-github-action@master with: args: | chmod 755 gradlew gradlew check