Docker Deployment
Developing your Docker Image Locally
Every time you make changes to any part of your Docker files (e.g.,
Dockerfile,app.py,requirements.txt), you need to build a new Docker image. Run the following command. Note thatmy-local-docker-imageis the image name in the example but you should provide a more meaningful name.docker build ./ -t my-local-docker-image
To run your newly built Docker container, run the command:
docker run my-local-docker-imageIf you need to interact with your container directly, run a command like:
```{bash} docker run -it --entrypoint=/bin/bash my-local-docker-image ```Once you are satisfied with local testing, then you may want to push that image to an external repository like ECR.
Posting Docker Image to ECR
ECR stands for Elastic Container Registry.
- Run the command to make a new repo in the elastic container registry to store your new containers. The repository name, in the example
my-docker-repo, needs to specified in a few places.
aws ecr create-repository --repository-name my-docker-repoRun the commands to grab info on your AWS account and region.
aws_region=$(aws configure get region) aws_account_id=$(aws sts get-caller-identity --query 'Account' --output text)Run the following command to configure your authentication to talk to the ECR service. Note how we use BASH variable with the
$so that you don’t have to manually enter your region or account id.aws ecr get-login-password \ --region $aws_region \ | docker login \ --username AWS \ --password-stdin $aws_account_id.dkr.ecr.$aws_region.amazonaws.comTag the image in the ECR registry by running the command. The final
my-docker-repois referring to the new repository you just built a few commands ago. Themy-local-docker-imageis the tag in your local Docker environment for the image you want to push.docker tag my-local-docker-image $aws_account_id.dkr.ecr.$aws_region.amazonaws.com/my-docker-repoPush the image to docker by running the command
docker push $aws_account_id.dkr.ecr.$aws_region.amazonaws.com/my-docker-repo
Read more about pushing a Docker image to ECR here.