7

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.

1
  • 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. Commented Sep 1, 2020 at 14:50

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.