Deploying a Bookstore Microservice on AWS with Docker, Ansible, and Vagrant
This step‑by‑step guide shows how to set up an AWS Tokyo VM, install Git and Ansible, clone microservice lifecycle and bookstore repositories, configure Vagrant, build Docker images, run tests with docker‑compose, and push the resulting images to a private registry.
The testing environment uses an AWS Tokyo virtual machine (2 CPU, 8 GB RAM). After confirming the disk size is at least 20 GB, the guide updates the package index and installs Git:
sudo apt-get update sudo apt-get install git -yIt then clones the microservice lifecycle repository and copies its contents into a /vagrant directory:
git clone https://github.com/vfarcic/ms-lifecycle.git sudo mkdir /vagrant sudo cp -r ms-lifecycle/* /vagrant/Inside /vagrant the Vagrantfile defines a VM named cd with a private network IP 10.100.198.200 and provisions it via an Ansible bootstrap script:
config.vm.define "cd" do |d|
d.vm.box = "ubuntu/trusty64"
d.vm.hostname = "cd"
d.vm.network "private_network", ip: "10.100.198.200"
d.vm.provision :shell, path: "scripts/bootstrap_ansible.sh"
d.vm.provision :shell, inline: "PYTHONUNBUFFERED=1 ansible-playbook /vagrant/ansible/cd.yml -c local"
d.vm.provider "virtualbox" do |v|
v.memory = 2048
end
endRunning the bootstrap script installs Ansible: sudo sh scripts/bootstrap_ansible.sh Next, the CD role playbook is executed:
sudo PYTHONUNBUFFERED=1 ansible-playbook /vagrant/ansible/cd.yml -c localThe playbook starts a local Docker registry and a mirror, confirming successful tasks with a recap showing 22 tasks, 19 changed.
After the environment is ready, the bookstore microservice code is cloned: git clone https://github.com/vfarcic/books-ms.git Network interfaces are configured so that eth0:1 serves the CD server IP and eth0:2 serves the dev server IP:
sudo ifconfig eth0:1 10.100.198.200/16 up sudo ifconfig eth0:2 10.100.199.200/16 upThe test Docker image is built (this step can take 15 minutes on an unfiltered AWS VM):
sudo docker build -f Dockerfile.test -t 10.100.198.200:5000/books-ms-tests .After the image 10.100.198.200:5000/books-ms-tests is created, the test suite is run with docker‑compose: sudo docker-compose -f docker-compose-dev.yml run --rm tests The build produces books‑ms‑assembly‑1.0.jar and stores it under target/scala-2.10/. The final production image is then built: sudo docker build -t 10.100.198.200:5000/books-ms . Containers are started manually for quick verification:
sudo docker run -d --name books-db mongo sudo docker run -d --name books-ms -p 8080:8080 --link books-db:db 10.100.198.200:5000/books-msEnvironment variables inside the running books‑ms container show the MongoDB connection details. The containers are listed with docker ps -a, and logs confirm the service is bound to port 8080.
For a more reproducible start, docker‑compose is used to bring up the application and database: sudo docker-compose -f docker-compose-dev.yml up -d app Logs from both services show successful startup. The frontend can be accessed via the public IP (e.g., http://52.197.175.5:8080/components/tc-books/demo/index.html), though initial tests indicated missing book entries.
API testing is performed with curl commands that create three book records and retrieve them using jq for JSON formatting.
After verification, the test environment is torn down:
sudo docker-compose stop sudo docker-compose rm -fFinally, both the production and test images are pushed to the private registry on the CD server:
sudo docker push 10.100.198.200:5000/books-ms sudo docker push 10.100.198.200:5000/books-ms-testsThroughout the chapter, screenshots illustrate the workflow steps (e.g., disk usage, Vagrantfile excerpt, and summary diagram).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
