For a nice intro to Java and Docker, check out this InfoWorld article. For this project we’ll build our simple Dockerfile by hand to get a look at it. There are several ways to create a Dockerfile, including using a Maven plug-in. Type each of the following commands in turn: sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release curl -fsSL | sudo gpg -dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb $(lsb_release -cs) stable" | sudo tee /etc/apt//docker.list > /dev/null sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io Create a Dockerfile Dockerize the projectįirst install Docker as per the official Docker instructions for Debian. If you navigate to the app in the browser, you’ll see the simple “Hello InfoWorld” response. Now you can stop Tomcat with Ctrl-c and rebuild/restart by typing. Add an endpoint import import .SpringBootApplication import .annotation.RequestMapping import .annotation.RestController public class DemoApplication Use vi src/main/java/com/example/javadocker/DemoApplication.java (or your editor of choice) to modify the main class to look like Listing 1. Just add a quick-and-dirty endpoint for testing. If you navigate to in the browser (you can find the IP address in the list on the GCP console), you should now receive the Spring White Label Error page, because there are no routes mapped. Spin up the app in dev mode by typing sudo. The Spring Boot app includes the mvnw script so you don’t need to install Maven manually. The new project will reside in /idg-java-docker. Now you can quickly create a new Spring Boot Java web app with the following command: spring init -dependencies=web idg-java-docker Next install the Spring CLI tool with sdk install springboot. Run the following commands: sudo apt install zip curl -s "" | bash source "/home//.sdkman/bin/sdkman.sh" Next, install the Spring CLI via SDKMAN (an SDK manager) so we can use Initializr from the shell. When that is done, java -version should return a value. Type sudo apt-get update, followed by sudo apt-get install default-jdk. SSH to the new server by clicking back to Computer Engine -> VM instances, finding the new instance (dev-1), and clicking the SSH button. With these in place, the new VM instance will allow traffic to the app server you will create on 8080 and to the default Java debug port of 8000. Create two new rules (click the Create Firewall Rule button) to allow all source IPs (0.0.0.0/0) to access TCP port 8080, with label port8080, and TCP port 8000, with label port8000. Now go to the left-hand menu and open VPC Networks -> Firewall. Click the Network tab in the middle of the VM details and in the Network Tags field, add port8080 and port8000. Go ahead and configure the network for this instance. However, Docker is a bit of a resource hog so I recommend using a general purpose E2 server (clocking in around $25 per month for 24/7 use). If you select an N1 micro server, it will be in the free tier. Now go to the Compute Engine link, which will give you a list of VMs and click Create Instance. Step one is to go to the GCP console (and sign up for a free account if you don't have one). This means you'll have an approach for remotely debugging a service like a QA server, as well as a local development host. As an additional benefit, we’ll do this process on a remotely running container. We’ll cover two essential needs: updating the running codebase without restarting the container and debugging into a running, containerized app. We are going to stand up a simple Java app in a VM on Google Cloud Platform (GCP), Dockerize it, then remotely debug it and modify its code from Visual Studio Code running on a local host. Also, the ability to remotely debug into a host running the Dockerized app can allow for hands-on troubleshooting of a running environment like QA. For example, a developer can use Docker to mimic a production environment to reproduce errors or other conditions. Even if you or your team are not committed to using Docker across dev machines as a matter of process, there are several use cases for modifying and debugging code running inside a container.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |