Docker  >  Build and Deploy

Build and Deploy

Running the Docker Image Locally

Before pushing the image to AWS, we need to run the image locally and should test if it works properly.

1
docker buildx build --platform linux/amd64 -t <APP_NAME>:local --load .

Above, we build the image. We can call it any APP_NAME and have a local copy of it.

1
docker run --rm -it -p 3000:3000 --env-file .env <APP_NAME>:local

Next, we run the image and also give it any environment variables that it needs. These are the same environment variables that we set up in the ECS task definition. This time they go in the .env file of your project

Pushing the Local Image to ECR

1
docker tag <APP_NAME>:local <ECR_REPO_URI>:<IMAGE_TAG>

We can start by link the local image we created to the ECR repo and add the 'latest' <IMAGE_TAG>

1
docker buildx build --platform linux/amd64 -t '<ECR_REPO_URI>:<IMAGE_TAG>' --push .

We can run a similar docker build command as the local run, but this time we are pushing the image to ECR, not load the image to run it.

Finally, go to your AWS ECS > Cluster > Service, and Force New Deployment


🙌 Congrats, you have completed creating a docker image and pushing it for your project!