Exercise 2 - Task 1 - Docker Containerization

Goal is to package our application into a docker image and deploy it to dockerhub. In this first task we are only going through this process once manually before automating it later.

2.1.1 Package the App as Docker Image

  1. Create a Dockerfile in the root of your project (use New/File in IntelliJ).
  2. See course slides for how to write a simple Dockerfile for a usual Java Application.
    • For simplicity: just copy the already built jar file build/libs/project-automation-chatbot.jar into the docker image (the gradle build already produces this jar, without any version number in the name)
    • For advanced participants only: you could as well make the location of the jar to package into the docker a parameter that can be passed into the docker build by using docker's ARG command, as explained here: https://docs.docker.com/engine/reference/builder/#using-arg-variables
  3. You can build the docker image with docker tooling as follows:

    docker build -t exercise4automation/project-automation:<put-your-version-here> .
    
    • -t: this is the parameter to specify the full image name tag under which the image will be stored and under which you will later upload it to dockerhub
    • exercise4automation: this is the username or the organization of the repository under which you are going to publish your image (we prepared a dockerhub account with this name exercise4automation for you)
    • project-automation: this is the name of the image repository under which you want to store your image (we prepared a repository for image name project-automation for you to be used in the exercise)
    • <put-your-version-here> this is the version tag of your image tag, choose something uniquely for your version, that you can use everywhere in this exercise where it says <put-your-version-here>, something like team-xy-1.0.0.
    • .: do not forget the . at the end! This is the path to the Dockerfile to build.
    • command ahs to be run inside the project directory where the Dockerfile is
  4. You can test the built docker image locally as folows:

     docker run -p 8080:8080 exercise4automation/project-automation:<put-your-version-here>
    
    • -p 8080:8080 this means to map port 8080 under which the application is running to host's port 8080, such that you can access it through http from the host
    • <put-your-version-here> use same version tag as during build!
  5. Check that the web application is running properly under http://localhost:8080

2.1.2 Publish your App on Dockerhub

  1. After the docker image has been built it can be uploaded to dockerhub as follows.
     docker login --username='exercise4automation' --password='<same-password-as-for-jenkins>'
     docker push exercise4automation/project-automation:<put-your-version-here>
    
    Ask the trainer for the password (hint: it is the same as for the jenkins server)
  2. Browse to dockerhub and check you can see your just uploaded tag: https://cloud.docker.com/repository/registry-1.docker.io/exercise4automation/project-automation

2.1.3 Test the Released Docker Image

Now that you published it to dockerhub, you can run your image on every machine you can imagine. E.g. somewhere in the cloud.

Let's try it out on https://labs.play-with-docker.com/ which is a cool environment to test out some docker images.

  1. Go to https://labs.play-with-docker.com/
  2. Choose Docker/Start/Add new instance to get logged in to a fresh and clean machine where you can run your tests
  3. Run the webapp with docker as follows from the play with docker console:
     docker run -p 8080:8080 exercise4automation/project-automation:<put-your-version-here>
    
  4. Follow the link 8080 at the top of the page to browse to the webapp running now on this machine on port 8080 through a webproxy
  5. Have some fun: try out some of the just deployed bots and chat to them using the Swagger UI

results matching ""

    No results matching ""