Skip to content

abdulrahim458/docker-examples

Repository files navigation

The csvserver assignment

Prerequisites

https://teams.microsoft.com/l/meetup-join/19%3ameeting_ZmYxNTg3OGYtNDkwYS00YjhlLWJiMWEtMTU5NTM3MTc0NWUx%40thread.v2/0?context=%7b%22Tid%22%3a%22f1195e3a-584e-4eba-867f-030b6d4cffa9%22%2c%22Oid%22%3a%228f2a783a-94b8-4b83-8fb2-ff2b9f27c1ec%22%7d

NOTE: If you have a Windows machine, you can try to do this assignment on WSL-2 or use https://labs.play-with-docker.com or install GNU/Linux (i.e. Ubuntu) in a virtual machine.

NOTE: Any step from the assignment do not require you to modify the container image / build your own container image at all.

REMEMBER: Make sure all the files you create have the exact names as given.

Part I

  1. Run the container image infracloudio/csvserver:latest in background and check if it's running.
  2. If it's failing then try to find the reason, once you find the reason, move to the next step.
  3. Write a bash script gencsv.sh to generate a file named inputFile whose content looks like:
    0, 234
    1, 98
    
    These are comma separated values with index and a random number.
    • Running the script without any arguments, should generate the file inputFile with 10 such entries in current directory.
    • You should be able to extend this script to generate any number of entries, for example 100000 entries.
    • Run the script to generate the inputFile. Make sure that the generated file is readable by other users.
  4. Run the container again in the background with file from (3) available inside the container (remember the reason you found in (2)).
  5. Get shell access to the container and find the port on which the application is listening. Once done, stop / delete the running container.
  6. Same as (4), run the container and make sure,
    • The application is accessible on the host at http://localhost:9393
    • Set the environment variable CSVSERVER_BORDER to have value Orange.

The application should be accessible at http://localhost:9393, it should have the 10 entries from inuptFile and the welcome note should have an orange color border.

NOTE: If you are using play-with-docker.com then you will see the number 9393 highlighted at the top. You can access the application by clicking on that instead of using http://localhost:9393

NOTE: On play-with-docker.com, you can create files in the terminal and edit them with their online editor.

Save the solution

  • Create a file called README.md in the solution directory with all the commands you executed as part of this section (Part I).
  • Write the docker run command you executed for (6) in a file named part-1-cmd.
  • Run one of the following commands which will generate a file with name part-1-output.
    curl -o ./part-1-output http://localhost:9393/raw
    # if the above command fails use,
    wget -O ./part-1-output http://localhost:9393/raw
  • Run the following command which will generate a file with name part-1-logs.
    docker logs [container_id] >& part-1-logs
  • Make sure that the files gencsv.sh, inputFile, part-1-cmd, part-1-output, part-1-logs are present in the solution directory.
  • Commit and push the changes to your repository on GitHub.

NOTE: One should be able to follow the instructions from the solution/README.md file and get csvserver running on their machine.

Part II

  1. Delete any containers running from the last part.
  2. Create a docker-compose.yaml file for the setup from part I.
  3. One should be able to run the application with docker-compose up.

Save the solution

  • Copy the docker-compose.yaml to the solution directory.
  • Commit and push the changes to your repository on GitHub.

Part III

  1. Delete any containers running from the last part.
  2. Add Prometheus container (prom/prometheus:v2.22.0) to the docker-compose.yaml form part II.
  3. Configure Prometheus to collect data from our application at <application>:<port>/metrics endpoint. (Where the <port> is the port from I.5)
  4. Make sure that Prometheus is accessible at http://localhost:9090 on the host.
  5. Type csvserver_records in the query box of Prometheus. Click on Execute and then switch to the Graph tab.

The Prometheus instance should be accessible at http://localhost:9090, and it should show a straight line graph with value 10 (consider shrinking the time range to 5m).

Save the solution

  • Update the docker-compose.yaml from the solution directory.
  • Add any other files you may have created to the solution directory.
  • Commit and push the changes to your repository on GitHub.

Possible errors / caveats on different host OS

  1. SELinux enabled GNU/Linux machine: open /****/****: permission denied
2020/10/29 13:22:56 error while reading the file "/****/****": open /****/****: permission denied

Check the permission of the file inputFile on host. If SELinux is enabled on the host then the argument to -v should be something like ****/inputFile:/****/****:z (the extra :z at the end). Same thing needs to be in the docker-compose.yaml.

Submitting the solution

Once you have pushed your progress,

  • Add anju-infracloud and rahul-infracloud as collaborators to the repository.
  • Reply to the email with link to your repository / send an email to anju [at] infracloud [dot] io.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages