This is my deployment code in GitHub action.
- name: Deploy to EC2
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
SERVICE_URL: ${{ secrets.SERVICE_URL }}
EMAILADMIN: ${{ secrets.EMAILADMIN }}
run: |
ssh -o "StrictHostKeyChecking=no" ec2-user@${{ secrets.EC2_IP }} << 'EOF'
set -x # Enable debugging to print all executed commands
echo "Step 1: Docker login"
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
echo "Step 2: Pulling Docker image"
docker pull ${{ secrets.DOCKER_USERNAME }}/lms-backend:latest
echo "Step 3: Stopping and removing existing container if it exists"
docker stop lms-backend-container || true
docker rm lms-backend-container || true
echo "Step 4: Listing all Docker images"
docker images
echo "Step 5: Running the new Docker container"
docker run -d -p 80:80 --name lms-backend-container
-e ACCESS_KEY=${{ secrets.ACCESS_KEY }}
-e SECRET_KEY=${{ secrets.SECRET_KEY }}
-e SERVICE_URL=${{ secrets.SERVICE_URL }}
-e EMAILADMIN=${{ secrets.EMAILADMIN }}
${{ secrets.DOCKER_USERNAME }}/lms-backend:latest
echo "Step 6: Listing all running containers"
docker ps -a
echo "Step 7: Checking for any references to 'piax'"
docker ps -a | grep piax || true
EOF
The thing is, every time I push any code to the main branch, it runs pretty much normally until it reaches this command.
docker run -d -p 80:80 --name lms-backend-container
-e ACCESS_KEY=${{ secrets.ACCESS_KEY }}
-e SECRET_KEY=${{ secrets.SECRET_KEY }}
-e SERVICE_URL=${{ secrets.SERVICE_URL }}
-e EMAILADMIN=${{ secrets.EMAILADMIN }}
${{ secrets.DOCKER_USERNAME }}/lms-backend:latest
Whenever it crossed this part, the same error appeared: “Unable to find image ‘piax:latest’ locally,” and I have no idea where the “piax” even came from.
I’ve checked the EC2 instance, and it shows that the Docker image was successfully pulled from Docker Hub with the correct names and labels.
It’s just that the command used to run that image into a container just doesn’t work correctlly.
Can anybody help me out on this? I’ve been stuck on this for a while now.
I’ve tried hardcode the Docker_username directly into my repository’s pipeline.yml and it still returns the same result
tried run the command (only the docker run command) directly on the Instance via SSH connection and it works so I don’t think the EC2 instance was at fault here
Tran Cong Minh K16_HL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.