Docker is not updating the image when using the same tag. In fact, when I set a fresh new tag in the github action such as TAG=latestV1, it turns out to build the image with the latest changes. Nevertheless, when using again the same latestV1 tag, the latest changes are not built in the image!!
I was thinking on using each github commit hash as the tag to address this issue. However, I will need to take care of deleting old images from the docker hub. I believe it shouldn’t be necessary to follow those extra steps. I just want to figure how can I override the image using the same tag with my latest changes.
My build job:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Login to docker hub
run: echo "${{secrets.DOCKER_PASSWORD}}" | docker login -u ${{secrets.DOCKER_USERNAME}} --password-stdin
- name: Build, tag and Push Images
run: |
REPO=${{secrets.DOCKER_USERNAME}}/****
TAG=latest
docker build --no-cache -t $REPO:client-$TAG --build-arg NEXT_PUBLIC_BACKEND_URL=${{secrets.NEXT_PUBLIC_BACKEND_URL}} --build-arg NEXT_PUBLIC_KEY_USER_SESSION=${{secrets.NEXT_PUBLIC_KEY_USER_SESSION}} ./frontend
docker build --no-cache -t $REPO:server-$TAG ./backend
docker build --no-cache -t $REPO:nginx-$TAG ./proxy
docker push $REPO:client-$TAG
docker push $REPO:server-$TAG
docker push $REPO:nginx-$TAG
This is the deploy job:
deploy:
needs: build
name: Deploy
runs-on: self-hosted
- name: ...
- name: Stop existing containers
run: docker-compose down
- name: Run container with Docker Compose
run: docker-compose up -d
1
The missing step was pulling images from the docker hub. Thus, I decided to update the docker-compose down as following to remove all local images stored in my aws ec2 instance:
docker-compose down --rmi all
This way the up command can pull up new images.