TL; DR: You may be using ContainerDirectory without HostDirectory, or you may need to update 03build.sh to build using the --no-cache = true flag.
After several hours later, I finally fixed it using my use case. I am using CodePipeline to run CodeCommit, CodeBuild and Elastic Beanstalk to create a continuous integration / continuous delivery solution in AWS with docker. The problem I ran into was that CodeBuild successfully created and published new docker images in AWS ECR (EC2 container registry), and EBS correctly pulled a new image, but the docker image was never updated on the server.
After checking the whole process of how EBS creates an image of dockers (there is a really wonderful article here, part 1 and part 2 here , which gives an overview), I found a problem.
To add to the article, EBS has a 3-step process in instances of EC2 that are deployed to deploy docker images.
This three-step process is a sequence of bash files that are executed that are located in /opt/elasticbeanstalk/hooks/appdeploy/
.
Preliminary preparation contains the following shell scripts:
- 00clean_dir.sh - Cleans the directory where the source will be loaded, deletes docker containers and images (for example, cleanup).
- 01unzip.sh - Download source code from S3 and unpack it.
- 02loopback-check.sh - Verifies that you do not have feedback loop settings
- 03build.sh - The magic happens here when EC2 will create your docker image from your Dockerfile or Dockerrun.aws.json. After much testing, I realized that this build script created my updated image, but I modified this script to include the -no-cache flag in the docker build.
The decision-making phase is where the caching issue really occurred. The stage consists of:
- 00run.sh - here the docker is run in relation to the image that was generated at the preliminary stage, based on the environment variables and settings in your Dockerrun.aws.json. This is what caused the caching problem for me.
- 01flip.sh - Converts from aws-staging to the current application and many other things.
When I launched docker from the image that was generated in Pre stage, 03build.sh, I will see the updated changes. However, when I execute the 00run.sh script shell, the old changes will appear. After checking the docker launch command, it ran
`Docker command: docker run -d -v null:/usr/share/nginx/html/ -v /var/log/eb-docker/containers/eb-current-app:/var/log/nginx ca491178d076`
-v null:/usr/share/nginx/html/
is what violated it and didn't update it. This was because my Dockerrun.aws.json file had
"Volumes": [ { "ContainerDirectory": "/usr/share/nginx/html/" } ],
without reference to the host location. As a result, any future changes I made were not updated.
For my solution, I just deleted the "Volumes"
array, since all my files are contained in the docker image that I upload to ECR. Note: You may need to add -no-cache to the 03build.sh file.