Docker walkthrough: Setting up local development with Docker containers in Skytap

This example describes how to set up a Docker container in Skytap that hosts a sample app; how to set up sharing between your local machine and the Docker container; and how to set up published services to publish a port on the container for easy access.

Before you begin

On the local machine, make sure the following software is installed:

Preparing a template in Skytap

  1. Create an environment from any Docker-supported version of Linux.
  2. Install Docker.
  3. Create a folder that will be mapped using Vagrant sync folders (for example, /liberty/config/dropins).
  4. In a terminal on the container host, run a Liberty container using the following command:

     docker run -d --name LibertyWithVolumes --restart=always -p 0.0.0.0:32960:9080 -v /liberty/config/dropins:/config/dropins websphere-liberty:webProfile7
    

    Port 32960 is mapped to port 9080 on the Liberty container.

  5. Configure the VM as a container host. For instructions, see Creating a container host in Skytap.
  6. Create a published service for port 32960 (which is mapped to port 9080 on the Liberty container).

    For instructions about creating a published service, see Accessing VMs with published services

  7. Stop the VM and save it as a template.

Creating a local Vagrant environment

  1. Create a local folder, such as ~/VagrantDemo.
  2. Create a vagrantfile in that folder from the template you just created. For instructions about creating a vagrant file, see Generate a Vagrantfile from an existing Skytap environment or template.
  3. Create a local sync folder, such as ~/VagrantDemo/sync.
  4. Edit the vagrantfile to add the sync folder using rsync.

     vm1.vm.synced_folder = "/Users/{full_path}/VagrantDemo/sync","/liberty/config/dropins",type:rsync
    

Create an Eclipse project

  1. In Eclipse, create a Dynamic Web Project (a simple Java project).
  2. Configure the app to write output when it receives a get.

    For example:

     response.getWriter().println("Container: " + hostname);
    

    For a step-by-step walkthrough, see https://youtu.be/A6pwGuBgiEI

Running the demo

  1. From ~/VagrantDemo, use vagrant to create an environment from the template specified in the vagrantfile with the command vagrant up.
  2. From a web browser, navigate to http://{published_service} to see that Liberty is running correctly.
  3. In Eclipse, right-click the project and select Export > WAR file.
  4. Save the WAR file to ~/VagrantDemo/sync.
  5. From ~/VagrantDemo, run the command vagrant rsync to synchronize the local file with the VM in Skytap.

    To configure Vagrant to automatically sync, in a separate terminal, run the command vagrant rsync-auto.

  6. From a web browser, navigate to http://{published_service}/{context_root} to see that the WAR file has been deployed.

    You created the published service in Preparing a template in Skytap, above.