Getting Started with Container and Cloud-based Development
Starting Development of Container and Cloud-based Applications Using Red Hat CodeReady Studio
Eva-Lotte Gebhardt
egebhard@redhat.com
Levi Valeeva
levi@redhat.com
Supriya Takkhi
sbharadw@redhat.com
Yana Hontyk
yhontyk@redhat.com
devtools-docs@redhat.com
Abstract
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.
Chapter 1. Developing using containers and the cloud in CodeReady Studio
1.1. Using Red Hat CodeReady Containers tools in CodeReady Studio
Red Hat CodeReady Containers (CRC) brings a minimal OpenShift 4 cluster to your local computer. This cluster provides a minimal environment for development and testing purposes. It is mainly targeted at running on developers' desktops. For other use cases, such as headless, multi-developer or team-based setups, use of the full-fledged OpenShift installer is recommended.
For a more in-depth introduction to OpenShift, see OpenShift documentation.
1.1.1. Downloading and installing Red Hat CodeReady Containers
The following section describes how to set up CodeReady Containers in CodeReady Studio.
Prerequisites
- Download the latest release of CodeReady Containers and the pull secret.
Extract the CRC file.
For more information on how to install and set up CRC, see the Installation chapter of the Getting started with CodeReady Containers Guide.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Server in the search field.
- Select Servers.
Click Open.
The Servers view appears.
Right-click any area in the Servers view.
Click New → Server.
The Define a New Server window appears.
- Select CodeReady Containers 1.0+.
Click Next.
The CodeReady Containers window appears.
- Click Browse to locate the CRC binary.
- Click Browse to locate the CRC Pull Secret File.
- Click Finish.
Your newly added CodeReady Containers 1.0+ server adapter is now listed in the Servers view.
In case you did not set up CRC prior to starting the server adapter, you will see a warning: CRC has not been properly initialized!
Follow the on-screen instructions to initialize CRC.
1.1.2. Using the OpenShift Container Platform tools
The following section describes how to use OpenShift Containers in CodeReady Studio.
Prerequisites
The CRC server adapter is set up and configured.
For more information, see Downloading and installing CRC.
Procedure
- Start CodeReady Studio.
Start the CRC server adapter.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
Press Ctrl+N.
The Select a wizard window appears.
- Enter OpenShift in the search field.
- Select OpenShift Application.
Click Next.
The Sign in to OpenShift window appears.
Provide your credentials and click Next.
The Create OpenShift Project window appears.
- Name your project.
Click Finish.
The Select template window appears.
- Select a template.
Click Next.
The Build Configuration window appears.
- Ensure that the build configurations are correct.
- Click Finish.
Your newly created OpenShift application project is now listed in the OpenShift Explorer view.
Additional resources
- For more information on how to perform additional tasks with the OpenShift Container Platform projects and application, see Developing for the Cloud with OpenShift in CodeReady Studio.
1.2. Using Red Hat Container Development Kit tools in CodeReady Studio
Red Hat Container Development Kit (CDK) is a pre-built container development environment based on Red Hat Enterprise Linux (RHEL). CDK helps you get started with developing container-based applications quickly.
1.2.1. Installing Container Development Kit
The following section describes how to install CDK from within CodeReady Studio.
Prerequisites
Ensure that the Hypervisor is installed and configured on your system:
- VirtualBox, Linux KVM/libvirt (Linux)
- xhyve (macOS)
- Hyper-V (Windows)
Ensure that hardware virtualization is enabled on your system.
For more information, see Setting Up the Virtualization Environment.
Ensure that you have a Red Hat Developer account.
To create a new account, visit developers.redhat.com.
For more information on CDK, see the Red Hat Container Development Kit Getting Started Guide.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Server in the search field.
- Select Servers.
Click Open.
The Servers view appears.
Right-click any area in the Servers view.
Click New → Server.
The Define a New Server window appears.
- Select Red Hat Container Development Kit 3.2+.
Click Next.
The Red Hat Container Development Environment window appears.
Click Download and install runtime.
The Download Runtimes window appears.
- Select a Red Hat CDK version.
- Click Next.
- Ensure that your sign-on credentials for access.redhat.com are correct.
- Click Next.
- Review and accept the license agreement and click Next.
Select the installation folder and click Finish.
Note that the process of downloading and installing the runtime might take some time to complete.
Click Finish.
Your newly created Container Development Environment 3.2+ server is now listed in the Servers view.
Right-click CDK server adapter → Start.
NoteIn case you did not set up CDK prior to starting the server adapter, you will see a warning: CDK has not been properly initialized!
Follow the on-screen instructions to initialize CDK.
1.2.2. Using Docker tools
1.2.2.1. Creating a Dockerfile
Prerequisites
The CDK server adapter is set up and configured.
For more information, see Installing CDK.
Procedure
- Start CodeReady Studio.
Start the CDK server adapter.
Press Ctrl+N.
The Select a wizard window appears.
- Enter Java Project in the search field.
- Select Java Project.
Click Next.
The New Java Project window appears.
- Name your project.
- Select the location for your project.
Click Finish.
Your newly created Java project is now listed in the CodeReady Studio view.
Right-click your Java project → New → File.
The Create New File window appears.
- Select the parent folder.
- Name your file.
Click Finish.
Your newly created file is now displayed in the CodeReady Studio editor.
Paste the following content into your newly created file:
# Use latest jboss/base-jdk:8 image as the base FROM jboss/base-jdk:8 # Set the WILDFLY_VERSION env variable ENV WILDFLY_VERSION 10.1.0.Final ENV WILDFLY_SHA1 9ee3c0255e2e6007d502223916cefad2a1a5e333 ENV JBOSS_HOME /opt/jboss/wildfly USER root # Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content # Make sure the distribution is available from a well-known place RUN cd $HOME \ && curl -O https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz \ && sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \ && tar xf wildfly-$WILDFLY_VERSION.tar.gz \ && mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \ && rm wildfly-$WILDFLY_VERSION.tar.gz \ && chown -R jboss:0 ${JBOSS_HOME} \ && chmod -R g+rw ${JBOSS_HOME} # Ensure signals are forwarded to the JVM process correctly for graceful shutdown ENV LAUNCH_JBOSS_IN_BACKGROUND true USER jboss # Expose the ports we're interested in EXPOSE 8080 # Set the default command to run on boot # This will boot WildFly in the standalone mode and bind to all interface CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
- Press Ctrl+S to save the changes.
Your Dockerfile has been created.
Additional resources
- For more information about Dockerfiles, see Dockerfile reference.
1.2.2.2. Building a Docker image Using Red Hat Container Development Kit
Prerequisites
The CDK server adapter is set up and configured.
For more information, see Installing CDK.
A Java project and a Dockerfile.
For more information, see Creating a Dockerfile.
Procedure
- Start CodeReady Studio.
Start the CDK server adapter.
- Expand your Java project.
Right-click Dockerfile → Run as → Docker Image Build.
The Docker Image Build Configuration window appears.
- Select your Container Development Environment server adapter as your connection.
- Name your image.
- Click OK.
The Console view appears displaying the docker image building process.
1.2.2.3. Additional resources
1.2.3. Additional resources
- For more information on how to perform tasks using the OpenShift Container Platform tooling, see Developing for the Cloud with OpenShift in CodeReady Studio.
- For more information on how to use OpenShift in CodeReady Studio, see OpenShift basics in CodeReady Studio.
Chapter 2. Developing for the Cloud with OpenShift in CodeReady Studio
2.1. Creating an OpenShift Container Platform application in CodeReady Studio
Using the OpenShift Container Platform tooling you can create, import, and modify OpenShift Container Platform applications.
2.1.1. Creating a new OpenShift Container Platform connection
You must create an OpenShift connection in the OpenShift Explorer view in CodeReady Studio to use the OpenShift tooling. An OpenShift connection connects CodeReady Studio to an OpenShift instance (based on CDK, OpenShift Online, Kubernetes, minishift). The connection is listed in the OpenShift Explorer view. You can have more than one OpenShift connection configured in CodeReady Studio.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
Right-click any area in the OpenShift Explorer.
Click New → Connection.
The Sign in to OpenShift window appears.
- Paste the URL of your OpenShift server into the Server field.
Authenticate with a token or login credentials.
NoteAlternatively, you can copy the Login Command from the OpenShift Container Platform web UI.
To get login credentials, click the drop-down menu in the top right corner → Copy Login Command.
- Click Finish.
Your newly added connection is now listed in the OpenShift Explorer view.
2.1.2. Creating a new OpenShift Container Platform project
You must create an OpenShift Container Platform project, which essentially is a namespace with additional annotations, to centrally manage the access to resources for regular users of your OpenShift Container Platform.
Prerequisites
An OpenShift Container Platform connection.
For more information on how to create a new OpenShift Container Platform connection, see Creating a new OpenShift Container Platform connection.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
Right-click the OpenShift Container Platform connection → New → Project.
The New OpenShift Project window appears.
- Name your project.
- Click Finish.
Your newly created OpenShift project is now listed in the OpenShift Explorer view.
2.1.3. Creating a new OpenShift Container Platform application
You can use the OpenShift Application wizard in CodeReady Studio to create OpenShift Container Platform applications from default or custom templates.
Prerequisites
An OpenShift Container Platform connection.
For more information on how to create a new OpenShift Container Platform connection, see Creating a new OpenShift Container Platform connection.
An OpenShift Container Platform project.
For more information on how to create a new OpenShift Container Platform project, see Creating a new OpenShift Container Platform project.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
Right-click the OpenShift Container Platform connection → New → Application.
The Select template window appears.
- Select a template.
Click Next.
The Template Parameters window appears.
Click Next.
The Resource Labels window appears.
- Click Add to add labels.
Click Finish.
The Create Application Summary window appears.
Click OK.
The Import OpenShift application window appears.
- Select your Git Clone Location.
- Click Finish.
Your newly created OpenShift Container Platform application is now listed in the OpenShift Explorer view.
Additional Resources
- For more information about using and creating templates with OpenShift Container Platform, see the upstream documentation Official OKD documentation, Using templates.
2.1.4. Importing an existing OpenShift Container Platform application into CodeReady Studio
The OpenShift Explorer view in CodeReady Studio lists applications associated with your OpenShift Container Platform accounts. You can import the source code for these applications individually into CodeReady Studio using the Import OpenShift Application wizard. After the application is imported, you can easily modify the application source code, build the application, and view it in a web browser.
Prerequisites
-
The application that you are importing into CodeReady Studio has its source specified in the
build config
file. An OpenShift Container Platform connection.
For more information on how to create an OpenShift Container Platform connection, see Creating a new OpenShift Container Platform connection.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
Right-click your OpenShift Container Platform connection → Import OpenShift Application.
The Select Build Config window appears.
- Select the application you want to import.
Click Next.
The Import OpenShift Application window appears.
- Select your Git Clone Location.
- Click Finish.
Your newly imported OpenShift Container Platform application is now listed in the OpenShift Explorer view.
2.1.5. Deploying an application using the server adapter
The server adapter enables you to publish the changes that you made in your workspace project to the running OpenShift application on the OpenShift instance. It enables incremental deployment of applications directly into the deployed pods on OpenShift. You can use the server adapter to push changes in your application directly to the running OpenShift application without committing the source code to the Git repository.
Prerequisites
An OpenShift Container Platform connection.
For more information on how to create an OpenShift Container Platform connection, see Creating a new OpenShift Container Platform connection.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
- Expand the OpenShift Container Platform connection.
Right-click your application → Server Adapter.
The Server Settings window appears.
- Click Finish.
The Servers view appears, starting your server adapter.
To open your application in a browser, right-click application → Show In → Web Browser.
The CodeReady Studio built-in web browser opens, displaying your application.
2.1.6. Deleting an OpenShift Container Platform project
You may choose to delete a project from the workspace for a fresh start in project development or after you have concluded development in a project. When you delete a project, all resources associated with the project are deleted as well.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
- Expand the OpenShift Container Platform connection.
Right-click your project → Delete.
The Delete OpenShift Resource window appears.
- Click OK.
Your project is now deleted.
2.2. Setting up and remotely monitoring an OpenShift Container Platform application in CodeReady Studio
CodeReady Studio allows users to set up a connection to a remote instance of OpenShift Container Platform and use application and build logs to troubleshoot and monitor running applications.
2.2.1. Setting up OpenShift Client Binaries
Prerequisites
- Before setting up port forwarding or streaming application and build logs, it is mandatory to set up OpenShift Client Binaries.
Procedure
- Start CodeReady Studio.
Click Window → Preferences.
The Preferences window appears.
- Enter OpenShift in the search field.
- Select OpenShift.
-
Click Browse to locate the
oc
executable. - Click Apply and Close.
OpenShift Client Binaries are now set up.
2.2.2. Setting up Port Forwarding
Using the Application Port Forwarding window, you can connect local ports to their remote counterparts to access data or debug your application.
Port forwarding automatically stops due to any of the following reasons:
- The OpenShift Container Platform connection terminates
- CodeReady Studio shuts down
- The workspace is changed
Port forwarding must be enabled each time to connect to OpenShift Container Platform from CodeReady Studio.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
- Expand the OpenShift Container Platform connection.
Right-click your application → Port Forwarding.
The Port Forwarding window appears.
- Check the Find free local ports for remote ports box.
- Click Start All.
- Click OK.
The Console view appears showing the port-forwarding starting process.
2.2.3. Streaming Pod Logs
Pod logs are general logs for an application running on a remote OpenShift Container Platform instance. The streaming pod logs feature in CodeReady Studio is used to monitor applications and use the previous pod log to troubleshoot if the application fails or returns errors.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
- Expand the OpenShift Container Platform connection.
Right-click the application → Pod Log.
The Console view appears displaying the Pod Log.
2.2.4. Streaming Build Logs
Build logs are logs that document changes to applications running on a remote OpenShift Container Platform instance. The streaming build logs feature in CodeReady Studio is used to view the progress of the application build process and to debug the application.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter OpenShift in the search field.
- Select OpenShift Explorer.
Click Open.
The OpenShift Explorer view appears.
- Expand the OpenShift Container Platform connection.
Right-click the application → Build Log.
The Console view appears displaying the Build Log.
2.3. Additional resources
- For more information on OpenShift Application Explorer, see Getting started with CodeReady Studio Tools.
:parent-context-of-developing-with-docker-in-devstudiogetting-started-with-container-and-cloud-based-development
Chapter 3. Developing with Docker in CodeReady Studio
3.1. Managing Docker connections
3.1.1. Setting up a Docker account
The following section describes how to set up a Docker account in CodeReady Studio.
Prerequisites
Docker is installed on your system.
For more information on how to install Docker, see Docker Docs - Get Docker.
You have a Docker ID.
For more information on how to get a Docker ID, see Register for a Docker ID.
Procedure
- Start CodeReady Studio.
Click Window → Preferences.
The Preferences window appears.
- Enter Registry Accounts in the search field.
- Select Registry Accounts.
Click Add.
The New Registry Account window appears.
- Enter the Server Address.
- Enter your Doker ID as the Username.
- Enter the email associated with your Docker account.
- Enter your password.
- Click OK.
- Click Apply and Close.
Your Docker account has been set up.
3.1.2. Testing an existing Docker connection
Prerequisites
A set up Docker account in CodeReady Studio.
For more information on how to set up a Docker account in CodeReady Studio, see Setting up a Docker account.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker in the search field.
- Select Docker Explorer.
Click Open.
The Docker Explorer view appears.
Right-click Docker socket → Edit.
The Edit Docker Connection window appears.
Click Test Connection.
If the connection is configured correctly, a window stating Ping succeeded! appears.
- Click OK.
- Click Finish.
3.1.3. Editing a Docker connection
Prerequisites
A set up Docker account in CodeReady Studio.
For more information on how to set up a Docker account in CodeReady Studio, see Setting up a Docker account.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker in the search field.
- Select Docker Explorer.
Click Open.
The Docker Explorer view appears.
Right-click Docker socket → Edit.
The Edit Docker Connection window appears.
- Click Browse in the Unix socket Location field to locate a new socket or check the TCP Connection option and add the URI.
- Click Finish.
3.2. Managing Docker images
3.2.1. Pulling Docker images
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker in the search field.
- Select Docker Explorer.
Click Open.
The Docker Explorer view appears.
- Expand the Docker socket folder.
Right-click Images → Pull.
The Pull Image window appears.
Click Search.
The Search the Docker Registry for images window appears.
- Enter your image name into the search field.
Click Next.
The Choose a tag for the selected image window appears.
- Choose a tag for your image.
Click Finish.
The Pull an image or a repository from the registry window appears.
- Click Finish.
You new Docker image is now listed in the Docker Explorer view.
3.2.2. Pushing Docker images
Before pushing an image you must tag it. The following section describes how to tag and push a Docker image in CodeReady Studio.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker in the search field.
- Select Docker Explorer.
Click Open.
The Docker Explorer view appears.
- Expand Docker socket → Images.
- Right-click the image you want to tag.
Click Add tag.
The Tag Image window appears.
Enter your tag in the New Tag field.
The tag should be in the form of
username/image_name:tag_name
, whereusername
is your Docker ID on hub.docker.com,image_name
is the name of your image, andtag_name
is the version of your image.- Click Finish.
Right-click the tagged image → Push.
The Push image to Registry window appears.
- Select the Registry Account that starts with your Docker ID.
- Click Finish.
After you push the image it appears in the Docker Cloud. This image is then available for other developers to use.
3.2.3. Running Docker images
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker in the search field.
- Select Docker Explorer.
Click Open.
The Docker Explorer view appears.
- Expand Docker socket → Images.
- Right-click images you want to run.
Click Run.
The Docker Container settings window appears.
- Name the container.
- Clear the Publish all exposed ports to random ports on the host interfaces check box.
-
Check the box for the
8080
port. Click Finish.
The Console view appears showing the process of starting the image.
In the web browser, navigate to http://localhost:8080/ to see the image running.
3.2.4. Building images with Dockerfile
You can build or create an image by modifying an existing image. Typically, this involves installing new packages. The specification of the new Docker image is done via a the Dockerfile
.
Prerequisites
You must have a Dockerfile created on your local machine.
For more information on how to create a Dockerfile, see Creating a Dockerfile.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker in the search field.
- Select Docker Images.
Click Open.
The Docker Images view appears.
Click the Build Image icon.
The Build a Docker Image window appears.
-
Name the image in the format of
repo/name:version
. - Click Browse to locate the Dockerfile.
- Click Finish.
The Console view appears displaying the build process.
3.3. Managing Docker Containers
Docker containers are isolated processes that are based on Docker images. Once created, users can stop, start, pause, unpause, kill, or remove the containers as well as read their logs.
The following section describes how to manage Docker containers in CodeReady Studio.
Procedure
- Start CodeReady Studio.
Click Window → Show View → Other.
The Show View window appears.
- Enter Docker into the search field.
- Select Docker Containers.
Click Open.
The Docker Containers view appears.
You can start, pause, unpause, stop, kill, restart, remove, or refresh the containers by using the panel.