Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 2
Message 1 of 3

Is it possible to login to dockerhub to initialize containers in GitHub Actions?

Is it possible to configure GitHub Actions to login to dockerhub when initializing containers to access private docker repositories? If so how is this configured?

 

I've tried a workflow script similar to the below example but the docker pull command fails because dockerhub requires a docker login command to access the private repo.

 

name: C/C++ CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    container:
       image: company/ubuntu-devel:latest
       env:
           DOCKERHUB_USER: user
           DOCKERHUB_PASS: password
           DOCKERHUB_EMAIL: user@company.com

    steps:
    - uses: actions/checkout@v1
    - name: make
    - run: make 

 

2 Replies
Mission Specialist Lvl 1
Message 2 of 3

Re: Is it possible to login to dockerhub to initialize containers in GitHub Actions?

Just to add to this, you can't even use GitHub's own package registry for images, ie, using

container: docker.pkg.github.com/user/repo/image:latest

results in an "no basic auth credentials" error.  Is there really no way to set login info when using a container?

 

Copilot Lvl 3
Message 3 of 3

Re: Is it possible to login to dockerhub to initialize containers in GitHub Actions?

There is currently no native way to pull private images from Docker Hub, but with a little bit of manual work, it's fairly trivial to run commands in a container from a private repository:

 

steps:
  - name: Docker login
    run: echo '${{ secrets.DOCKERHUB_PASS }}' | docker login --username <YOUR_USER> --password-stdin

  - name: Pull image
    run: docker pull company/ubuntu-devel:latest

  - name: Run command in container
    run: docker run --rm company/ubuntu-devel:latest make

This will login to Docker Hub, using the given username and password (in this example I created a secret called DOCKERHUB_PASS to my repository) and it will run `make` inside the container based on your private image. Of course you can make it do whatever you want in there.