If Docker is not already installed lets proceed to install it, by either using the official documentation, or the script from GetDocker. Furthermore, we will install Docker Compose for development, and/or building the container images; Docker compose installation guide can be found here.
Set up the manager node.
sudo docker swarm init --advertise-addr $(hostname -i)
Save the stack file (docker-compose.yml) into the machine and create a new stack.
sudo docker stack deploy --compose-file docker-compose.yml earthquakes
To initialize the application using Docker Compose, we can simple go to the project's folder and run the following command.
sudo docker-compose up
However, as the database is going to be missing at this point, we need to complete the below steps, and might need to restart the application afterwards, as the api service would have failed, and might not recover on its own.
Go to the Adminer UI (Current user is root, and password can be found on the docker-compose file, under MYSQL_ROOT_PASSWORD
). Once logged in, click on Create Database
and create one called locations
.
Locations can be added either directly by API calls, or by using Adminer.
Some example API calls are set below for convenience.
curl --location --request POST 'http://127.0.0.1:80/locations/add' \
--form 'identifier="tokyo_japon"' \
--form 'name="Tokyo, Japon"' \
--form 'latitude="35.6895"' \
--form 'longitude="139.69171"'
curl --location --request POST 'http://127.0.0.1:80/locations/add' \
--form 'identifier="los_angeles_ca"' \
--form 'name="Los Angeles, CA"' \
--form 'latitude="34.052235"' \
--form 'longitude="-118.243683"'
curl --location --request POST 'http://127.0.0.1:80/locations/add' \
--form 'identifier="san_francisco_ca"' \
--form 'name="San Francisco, CA"' \
--form 'latitude="37.733795"' \
--form 'longitude="-122.446747"'
Now that everything is set up, go to the application, which in a local machine will be at the standard localhost, and 3 locations should be visible.
Start development server, forcing a rebuild:
sudo docker-compose up --build
Start production server using Docker Compose, forcing a rebuild.
sudo docker-compose -y docker-compose.yml -f docker-compose.prod.yml up --build
Remove the application:
sudo docker-compose down