Skip to content

Remove Specific exist image and container

Actions
Removing Specific exist image and container
v1.0.2
Latest
Star (2)

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).

Remove Specific exist image and container is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Removing Specific exist image and container
v1.0.2
Latest

Remove Specific exist image and container is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.