Home > Software engineering >  docker create context ecs fails in github actions
docker create context ecs fails in github actions

Time:02-15

I'm trying to deploy my docker containers to ECS using docker compose. Everything works as expected locally, but when I try to do the same in a github actions workflow, I get the following error when trying to run docker create context ecs ecscontext:

"docker context create" requires exactly 1 argument.

I first assumed the error was because the docker and docker-compose version on the github runner were different my local ones, so I uninstalled them and reinstalled them. Here is the the modified workflow file:

name: deploy

on:
  workflow_dispatch:
  repository_dispatch:
    types: [update_stack]

jobs:
  deploy:
    name: "Deploy stack"
    runs-on: ubuntu-latest
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
      AWS_DEFAULT_REGION: us-east-1
    steps:
      -
        name: Update docker version
        run: |
          sudo apt-get remove docker docker-engine docker.io containerd runc
          sudo apt-get update -y
          sudo apt-get install -y ca-certificates curl gnupg lsb-release
          curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
          echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
          sudo apt-get update -y
          sudo apt-get install -y docker-ce docker-ce-cli containerd.io
      -
        name: Update docker-compose version
        run: |
          sudo rm /usr/local/bin/docker-compose
          sudo mkdir -p /usr/local/lib/docker/cli-plugins
          sudo curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
          sudo chmod  x /usr/local/lib/docker/cli-plugins/docker-compose
      -
        name: check docker new version 
        run: docker -v
      -
        name: check docker compose new version 
        run: docker compose version
      -
        name: Create ECS docker context
        run: sudo docker context create ecs ecscontext --from-env

The docker -v output is the same the one I have locally: Docker version 20.10.12, build e91ed57

The docker compose version output is the same as the one I have locally: Docker Compose version v2.2.3

Yet it still fails at the create context step. Any help is appreciated.

CodePudding user response:

Turns out that the docker and docker-compose binaries were irrelevant, I had to update the docker CLI by running sudo curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sudo sh. The new workflow looks like this:

name: deploy

on:
  workflow_dispatch:
  repository_dispatch:
    types: [update_stack]

jobs:
  deploy:
    name: "Deploy stack"
    runs-on: ubuntu-latest
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
      AWS_DEFAULT_REGION: us-east-1
    steps:
      -
        name: Update docker-compose version
        run: |
          sudo curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sudo sh
      -
        name: check docker new version 
        run: docker -v
      -
        name: check docker compose new version 
        run: docker compose version
      -
        name: Create ECS docker context
        run: sudo docker context create ecs ecscontext --from-env
  • Related