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
- Create an environment from any Docker-supported version of Linux.
- Install Docker.
- Create a folder that will be mapped using Vagrant sync folders (for example,
/liberty/config/dropins
). -
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.
- Configure the VM as a container host. For instructions, see Creating a container host in Skytap.
-
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
- Stop the VM and save it as a template.
Creating a local Vagrant environment
- Create a local folder, such as
~/VagrantDemo
. - 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.
- Create a local sync folder, such as
~/VagrantDemo/sync
. -
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
- In Eclipse, create a Dynamic Web Project (a simple Java project).
-
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
- From
~/VagrantDemo
, use vagrant to create an environment from the template specified in the vagrantfile with the commandvagrant up
. - From a web browser, navigate to
http://{published_service}
to see that Liberty is running correctly. - In Eclipse, right-click the project and select Export > WAR file.
- Save the WAR file to
~/VagrantDemo/sync
. -
From
~/VagrantDemo
, run the commandvagrant 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
. -
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.