5

I'm learning Github Actions and designing a workflow with a job that requires a Service Container.

The documentation states that configuration must specify "The Docker image to use as the service container to run the action. The value can be the Docker base image name or a public docker Hub or registry". All of the examples in the docs use publicly-available Docker images, however I want to create a Service Container from a Dockerfile contained within my repo.

Is it possible to use a local Dockerfile to create a Service Container?

Because the job depends on a Service Container, that image must exist when the job begins, and therefore the image cannot be created by an earlier step in the same job. The image could be built in a separate job, but because jobs execute in separate runners I believe that Job 2 will not have access to the image created in Job 1. If this is true then could I follow this approach, using upload/download-artifact so provide Job 1's image to Job 2?

If all else fails, I could have Job 1 create the image and upload it to Docker Hub, then have Job 2 download it from Docker Hub, but surely there is a better way.

tomfumb
  • 3,669
  • 3
  • 34
  • 50
  • 1
    We do not offer a way to use a plain Dockerfile as a service container due to the limitation that services are configured before we start the job steps and at that time we do not have the repository cloned and depending on how the job is setup we may never have the repository cloned. – Chris Patterson Sep 01 '20 at 14:50

2 Answers2

2

The GitHub Actions host machine (runner) is a fully loaded Linux machine, with everything everybody needs already installed.

You can easily launch multiple containers - either your own images, or public images - by simply running docker and docker-compose commands.

My advice to you is: Describe your service(s) in a docker-compose.yml file, and in one of your GitHub Actions steps, simply do docker-compose up -d.

DannyB
  • 12,810
  • 5
  • 55
  • 65
1

You can create a docker image with the Dockerfile or docker-compose.yml residing inside the repo. Refer to this public gist, it might be helpful.

Instead of building multiple docker-images, you can use docker-compose. Docker-compose is the preferred way to deal with this kind of scenario.

Lavish
  • 642
  • 7
  • 12