Skip to content

Lovegupta112/cleanup-docker-container-img

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Remove Specific Existing Docker Container and Image

GitHub Action to remove a specific existing Docker container and its associated Docker image from a remote VM.

Example :

on:
  push: main
jobs:
  buildAndRunImage:
    name: Build, Push, and Cleanup Docker Container
    runs-on: ubuntu:latest
    steps:
      - name: checkout the repo
        uses: actions/checkout@v4
      - name: login to the docker hub
        uses: docker/login-action@v3
        with:
          username: ${{secrets.DOCKERHUB_USERNAME}}
          password: ${{secrets.DOCKERHUB_PASSWORD}}
      - name: build and push to docker hub
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ./Dockerfile # Update the correct path if necessary
          push: true
          tags: your-dockerhub-username/your-image-name:latest
      - name: Remove Existing Container and Image
        uses: Lovegupta112/[email protected]
        with:
          SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}}
          HOST_IP: ${{secrets.HOST_IP}}
          CONTAINER_NAME: ${{secrets.BACKEND_CONTAINER_NAME}}
      - name: start the container #start your container 
        run: |
          echo "${{ secrets.SSH_PRIVATE_KEY }}" &> ~/ssh_key 
          chmod 700 ~/ssh_key 
          ssh -o StrictHostKeyChecking=no -i ~/ssh_key ${{secrets.HOST_IP}} -t << 'EOF'
          docker run -d -p 8080:8080 \
          -e DATABASE_URL=${{secrets.DATABASE_URL}} \
          --name ${{secrets.BACKEND_CONTAINER_NAME}} \
           your-dockerhub-username/your-image-name:latest
          EOF
           

Inputs:

  1. SSH_PRIVATE_KEY & HOST_IP ( Required ) : for accessing the remote vm there is need of ssh private key and iP address of the remote VM (i.g. [email protected]) .

  2. CONTAINER_NAME ( Required ) : Name of the container to be removed (along with its associated image).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published