0% found this document useful (0 votes)
35 views

Getting Started With Container and Cloud Based Development

Uploaded by

Eliamfd Mazz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Getting Started With Container and Cloud Based Development

Uploaded by

Eliamfd Mazz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Red Hat CodeReady Studio 12.

17

Getting Started with Container and Cloud-


based Development

Starting Development of Container and Cloud-based Applications Using Red Hat


CodeReady Studio

Last Updated: 2020-10-12


Red Hat CodeReady Studio 12.17 Getting Started with Container and
Cloud-based Development
Starting Development of Container and Cloud-based Applications Using Red Hat CodeReady
Studio

Levi Valeeva
[email protected]

Supriya Takkhi
[email protected]

Yana Hontyk
[email protected]
Legal Notice
Copyright © 2020 Red Hat, Inc.

The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.

Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.

Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.

Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.

Java ® is a registered trademark of Oracle and/or its affiliates.

XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.

MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.

Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.

The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.

All other trademarks are the property of their respective owners.

Abstract
This compilation of topics contains information on how to start developing containerized
applications and applications for cloud deployment.
Table of Contents

Table of Contents
.CHAPTER
. . . . . . . . . . 1.. .DEVELOPING
. . . . . . . . . . . . . . .USING
. . . . . . .CONTAINERS
. . . . . . . . . . . . . . .AND
. . . . .THE
. . . . .CLOUD
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
1.1. USING RED HAT CODEREADY CONTAINERS TOOLING IN CODEREADY STUDIO 3
1.1.1. Downloading and installing Red Hat CodeReady Containers in CodeReady Studio 3
1.1.2. Using the OpenShift Container Platform tooling 6
1.2. USING RED HAT CONTAINER DEVELOPMENT KIT TOOLING IN CODEREADY STUDIO 12
1.2.1. Installing Container Development Kit in CodeReady Studio 12
1.2.2. Using Docker tooling 17
1.2.2.1. Creating a Dockerfile 17
1.2.2.2. Building the Docker image Using the Container Development Environment 23
1.2.2.3. Additional resources 25
1.2.3. Using the OpenShift Container Platform tooling 25
1.2.4. Additional resources 31

.CHAPTER
. . . . . . . . . . 2.
. . DEVELOPING
. . . . . . . . . . . . . . . FOR
. . . . . THE
. . . . .CLOUD
. . . . . . . . WITH
. . . . . . OPENSHIFT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
..............
2.1. CREATING AN OPENSHIFT CONTAINER PLATFORM APPLICATION IN CODEREADY STUDIO 32
2.1.1. Creating a new OpenShift Container Platform connection 32
2.1.2. Creating a new OpenShift Container Platform project 35
2.1.3. Creating a new OpenShift Container Platform application 37
2.1.4. Importing an existing OpenShift Container Platform application into the IDE 42
2.1.5. Deploying an application using the server adapter 45
2.1.6. Deleting an OpenShift Container Platform project 48
2.2. SETTING UP AND REMOTELY MONITORING AN OPENSHIFT CONTAINER PLATFORM APPLICATION
50
2.2.1. Setting up OpenShift Client Binaries 50
2.2.2. Setting up Port Forwarding 51
2.2.3. Streaming Pod Logs 54
2.2.4. Streaming Build Logs 56
2.3. ADDITIONAL RESOURCES 58

. . . . . . . . . . . 3.
CHAPTER . . DEVELOPING
. . . . . . . . . . . . . . . WITH
. . . . . . DOCKER
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
..............
3.1. MANAGING DOCKER CONNECTIONS 59
3.1.1. Setting up the Docker account in CodeReady Studio 59
3.1.2. Testing the Docker connection 60
3.1.3. Editing the Docker connection 63
3.2. MANAGING DOCKER IMAGES 65
3.2.1. Pulling Docker images 65
3.2.2. Pushing Docker images 70
3.2.3. Running Docker images 74
3.2.4. Building images with Dockerfile 78
3.3. MANAGING DOCKER CONTAINERS 80

1
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

2
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

CHAPTER 1. DEVELOPING USING CONTAINERS AND THE


CLOUD

1.1. USING RED HAT CODEREADY CONTAINERS TOOLING 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.

Prerequisites

1. Download the latest release of CodeReady Containers and the pull secret .

2. 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.

1.1.1. Downloading and installing Red Hat CodeReady Containers in


CodeReady Studio
The following section describes how to set up CodeReady Containers in CodeReady Studio. The section
assumes you completed the steps listed in the prerequisites section for this chapter.

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

3
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Enter Server in the search field.

4. Select Servers.

5. Click Open.
The Servers view appears.

6. Right-click any area in the Servers view.

4
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

7. Click New → Server.


The Define a New Server window appears.

5
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

8. Select CodeReady Containers 1.0+.

9. Click Next.
The CodeReady Containers window appears.

10. Click Browse to locate the CRC binary.

11. Click Browse to locate the CRC Pull Secret File.

12. Click Finish.

Your newly added CodeReady Containers 1.0+ server adapter is now listed in the Servers view.

1.1.2. Using the OpenShift Container Platform tooling


The following section describes how to use OpenShift Containers in CodeReady Studio.

Prerequisites

Set up and configure the CRC server adapter.


For more information, see Section 1.1.1, “Downloading and installing Red Hat
CodeReady Containers in CodeReady Studio”.

Procedure

1. Start CodeReady Studio.

6
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

2. Start the CRC server adapter.

3. Click Window → Show View → Other.


The Show View window appears.

7
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

4. Enter OpenShift in the search field.

5. Select OpenShift Explorer.

6. Click Open.
The OpenShift Explorer view appears.

7. Press Ctrl+N.
The Select a wizard window appears.

8. Enter OpenShift in the search field.

9. Select OpenShift Application.

10. Click Next.


The Sign in to OpenShift window appears.

8
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

11. Click Next.


The Create OpenShift Project window appears.

12. Name your project.

13. Click Finish.


The Select template window appears.

9
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

14. Select the template.

15. Click Next.


The Build Configuration window appears.

10
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

16. Ensure that the build configurations are correct.

17. Click Finish.

Your newly created OpenShift application project is now listed in the OpenShift Explorer view.

11
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

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.

1.2. USING RED HAT CONTAINER DEVELOPMENT KIT TOOLING 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. You can easily set up CDK within CodeReady Studio.

1.2.1. Installing Container Development Kit in CodeReady Studio


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.


For a new account, visit https://developers.redhat.com/.

For more information on CDK, see the Red Hat Container Development Kit Getting Started Guide .

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

12
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

3. Enter Server in the search field.

4. Select Servers.

5. Click Open.
The Servers view appears.

6. Right-click any area in the Servers view.

13
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

7. Click New → Server.


The Define a New Server window appears.

14
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

8. Select Red Hat Container Development Kit 3.2+.

9. Click Next.
The Red Hat Container Development Environment window appears.

10. Click Download and install runtime.


The Download Runtimes window appears.

15
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

11. Select a Red Hat CDK version.

12. Click Next.

13. Ensure that your sign-on credentials for access.redhat.com are correct.

14. Click Next.

15. Review and accept the license agreement and click Next.

16. Select the installation folder and click Finish.


Note that the process of downloading and installing the runtime might take some time to
complete.

17. Click Finish.


Your newly created Container Development Environment 3.2+ server is now listed in the
Servers view.

16
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

18. Right-click CDK server adapter → Start.

NOTE

In 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 tooling


After starting the CDK server in the IDE, you can follow one of the two container development workflows
to use the Docker tooling.

1.2.2.1. Creating a Dockerfile

Prerequisites

Set up and configure the CDK server adapter.


For more information, see Section 1.2.1, “Installing Container Development Kit in
17
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

For more information, see Section 1.2.1, “Installing Container Development Kit in
CodeReady Studio”.

Procedure

1. Start CodeReady Studio.

2. Start the CDK server adapter.

3. Press Ctrl+N.
The Select a wizard window appears.

18
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

4. Enter Java Project in the search field.

5. Select Java Project.

6. Click Next.
The New Java Project window appears.

19
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

7. Name your project.

8. Select the location for your project.

9. Click Finish.
Your newly created Java project is now listed in the CodeReady Studio view.

10. Right-click your Java project → New → File.

20
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

The Create New File window appears.

21
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

11. Select the parent folder.

12. Name your file.

13. Click Finish.


Your newly created file is now displayed in the CodeReady Studio editor.

14. 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

22
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

# 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"]

15. Press Ctrl+S to save the changes.

Additional resources

For more information about Dockerfiles, see Dockerfile reference.

1.2.2.2. Building the Docker image Using the Container Development Environment

Prerequisites

Set up and configure the CDK server adapter.


For more information, see Section 1.2.1, “Installing Container Development Kit in
CodeReady Studio”.

Create a Java project and a Docrefile.


For more information, see Section 1.2.2.1, “Creating a Dockerfile”

Procedure

1. Start CodeReady Studio.

2. Start the CDK server adapter.

23
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Expand your Java project.

4. Right-click Dockerfile → Run as → Docker Image Build.

The Docker Image Build Configuration window appears.

24
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

5. Select your Container Development Environment server adapter as your connection.

6. Name your image.

7. Click OK.

The Console view appears displaying the docker image building process.

1.2.2.3. Additional resources

For more information about the basics of Docker Tooling, see Using Docker Tooling in
CodeReady Studio.

1.2.3. Using the OpenShift Container Platform tooling


The following section describes how to use OpenShift Containers in CodeReady Studio.

Prerequisites

Set up and configure the CRC server adapter.


For more information, see Section 1.1.1, “Downloading and installing Red Hat
CodeReady Containers in CodeReady Studio”.

Procedure

1. Start CodeReady Studio.

2. Start the CRC server adapter.

25
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Click Window → Show View → Other.


The Show View window appears.

26
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

4. Enter OpenShift in the search field.

5. Select OpenShift Explorer.

6. Click Open.
The OpenShift Explorer view appears.

7. Press Ctrl+N.
The Select a wizard window appears.

8. Enter OpenShift in the search field.

9. Select OpenShift Application.

10. Click Next.


The Sign in to OpenShift window appears.

27
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

11. Click Next.


The Create OpenShift Project window appears.

12. Name your project.

13. Click Finish.


The Select template window appears.

28
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

14. Select the template.

15. Click Next.


The Build Configuration window appears.

29
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

16. Ensure that the build configurations are correct.

17. Click Finish.

Your newly created OpenShift application project is now listed in the OpenShift Explorer view.

30
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD

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.

1.2.4. Additional resources


For more information on how to perform tasks using the OpenShift Container Platform tooling,
see Developing for the Cloud with OpenShift 4 .

For more information on how to use OpenShift in CodeReady Studio, see OpenShift basics in
CodeReady Studio

31
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

CHAPTER 2. DEVELOPING FOR THE CLOUD WITH


OPENSHIFT

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 in the IDE. An OpenShift connection connects your IDE 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 the IDE.

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

32
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Right-click any area in the OpenShift Explorer.

33
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

7. Click New → Connection.


The Sign in to OpenShift window appears.

8. Paste the URL for the OpenShift server into the Server field.

9. Authenticate with token or login credentials.

NOTE
34
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

NOTE

Alternatively, 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

10. 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 a project, which essentially is a namespace with additional annotations, to centrally
manage the access to resources for regular users.

Prerequisites

An OpenShift Container Platform connection.


For more information on how to create a new OpenShift Container Platform connection, see
Section 2.1.1, “Creating a new OpenShift Container Platform connection” .

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

35
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Right-click the OpenShift Container Platform connection → New → Project.

The New OpenShift Project window appears.

36
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

7. Name your project.

8. 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 the IDE 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
Section 2.1.1, “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
Section 2.1.2, “Creating a new OpenShift Container Platform project” .

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

37
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Right-click the OpenShift Container Platform connection → New → Application.

The Select template window appears.

38
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

7. Select the template.

8. Click Next.
The Template Parameters window appears.

9. Click Next.
The Resource Labels window appears.

39
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

10. Click Add to add labels.

11. Click Finish.


The Create Application Summary window appears.

40
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

12. Click OK.


The Import OpenShift application window appears.

41
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

13. Select the Git Clone Location.

14. 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 Using templates.

2.1.4. Importing an existing OpenShift Container Platform application into the IDE
The OpenShift Explorer view in the IDE lists applications associated with your OpenShift Container
Platform accounts. You can import the source code for these applications individually into the IDE 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 in the IDE has its source specified in the build config file.

An OpenShift Container Platform connection.


For more information on how to create a new OpenShift Container Platform connection, see
Section 2.1.1, “Creating a new OpenShift Container Platform connection” .

Procedure

42
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Right-click your OpenShift Container Platform connection → Import OpenShift Application.

43
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

The Select Build Config window appears.

44
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

7. Select the application to import.

8. Click Next.
The Import OpenShift application window appears.

9. Select the Git Clone Location.

10. 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 a new OpenShift Container Platform connection, see
Section 2.1.1, “Creating a new OpenShift Container Platform connection” .

Procedure

45
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Expand the OpenShift Container Platform connection.

7. Right-click your application → Server Adapter.

46
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

The Server Settings window appears.

8. Click Finish.

The Servers view appears, starting your server adapter.

To open your application in a browser, right-click application → Show In → Web Browser.

47
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

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 to make a fresh start in project development or
after you have concluded development in a project. When you delete a project, all the resources
associated with the project are deleted.

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

48
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Expand the OpenShift Container Platform connection.

7. Right-click your project → Delete.

49
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

The Delete OpenShift Resource window appears.

8. Click OK.

Your project is now deleted.

2.2. SETTING UP AND REMOTELY MONITORING AN OPENSHIFT


CONTAINER PLATFORM APPLICATION
The IDE allows users to set up a connection to a remote instance of OpenShift Container Platform and
then use logs (application logs 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

1. Start CodeReady Studio.

2. Click Window → Preferences.


The Preferences window appears.

50
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

3. Enter OpenShift in the search field.

4. Select OpenShift.

5. Click Browse to locate the oc executable.

6. 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 the local ports to their remote
counterparts to access data or debug the application. Port forwarding automatically stops due to any
one of the following reasons:

The OpenShift Container Platform connection terminates

The IDE shuts down

The workspace is changed

Port forwarding must be enabled each time to connect to OpenShift Container Platform from the IDE.

Procedure

51
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Expand the OpenShift Container Platform connection.

7. Right-click the application → Port Forwarding.

52
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

The Port Forwarding window appears.

53
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

8. Check the Find free local ports for remote portsbox.

9. Click Start All.

10. 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 application logs feature in the IDE is used to monitor applications and use the previous
pod log to troubleshoot if the application fails or returns errors.

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

54
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Expand the OpenShift Container Platform connection.

7. Right-click the application → Port Log.

55
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

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 the IDE is used to view the progress of the
application build process and to debug the application.

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

56
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT

3. Enter OpenShift in the search field.

4. Select OpenShift Explorer.

5. Click Open.
The OpenShift Explorer view appears.

6. Expand the OpenShift Container Platform connection.

7. Right-click the application → Build Log.

The Console view appears displaying the Build Log.

57
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

2.3. ADDITIONAL RESOURCES


For more information on OpenShift Application Explorer, see Getting started with CodeReady
Studio Tools.

58
CHAPTER 3. DEVELOPING WITH DOCKER

CHAPTER 3. DEVELOPING WITH DOCKER

Prerequisites

Installed Docker on your system.


For more information on how to install Docker, see Get Docker.

Get a Docker ID.


For more information on how to get a Docker ID, see Register for a Docker ID .

3.1. MANAGING DOCKER CONNECTIONS

3.1.1. Setting up the Docker account in CodeReady Studio


The following section describes how to set up a Docker account in CodeReady Studio. The section
assumes you completed the steps listed in the prerequisites section for this chapter.

Procedure

1. Start CodeReady Studio.

2. Click Window → Preferences.


The Preferences window appears.

59
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Enter Registry Accounts in the search field.

4. Select Registry Accounts.

5. Click Add.
The New Registry Account window appears.

6. Enter the Server Address.

7. Enter your Doker ID as the Username.

8. Enter the email associated with your Docker account.

9. Enter your password.

10. Click OK.

11. Click Apply and Close.

3.1.2. Testing the Docker connection

Prerequisites

Set up Docker account in CodeReady Studio.


For more information on how to set up a Docker account in CodeReady Studio, see Section 3.1.1,
“Setting up the Docker account in CodeReady Studio”

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

60
CHAPTER 3. DEVELOPING WITH DOCKER

3. Enter Docker in the search field.

4. Select Docker Explorer.

5. Click Open.
The Docker Explorer view appears.

6. Right-click Docker socket → Edit.

61
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

The Edit Docker Connection window appears.

7. Click Test Connection.


If the connection is configured correctly, a window stating that the Ping succeeded! appears.

8. Click OK.

62
CHAPTER 3. DEVELOPING WITH DOCKER

9. Click Finish.

3.1.3. Editing the Docker connection

Prerequisites

Set up Docker account in CodeReady Studio.


For more information on how to set up a Docker account in CodeReady Studio, see Section 3.1.1,
“Setting up the Docker account in CodeReady Studio”

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

3. Enter Docker in the search field.

4. Select Docker Explorer.

63
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

5. Click Open.
The Docker Explorer view appears.

6. Right-click Docker socket → Edit.

The Edit Docker Connection window appears.

64
CHAPTER 3. DEVELOPING WITH DOCKER

7. Click Browse in Unix socket Location field to locate a new socket or check the TCP
Connection option and add the URI.

8. Click Finish.

3.2. MANAGING DOCKER IMAGES

3.2.1. Pulling Docker images

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

65
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

3. Enter Docker in the search field.

4. Select Docker Explorer.

5. Click Open.
The Docker Explorer view appears.

6. Expand Docker socket folder.

66
CHAPTER 3. DEVELOPING WITH DOCKER

7. Right-click Images → Pull.

The Pull Image window appears.

8. Click Search.
The Search the Docker Registry for imageswindow appears.

67
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

9. Enter the image name in the search field.

10. Click Next.


The Choose a tag for the selected imagewindow appears.

68
CHAPTER 3. DEVELOPING WITH DOCKER

11. Choose a tag for your image.

12. Click Finish.


The Search the Docker Registry for imageswindow appears.

69
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

13. Click Finish.

You new Docker image is now listed in the Docker Explorer view.

3.2.2. Pushing Docker images


Before pushing the image, you must tag it. The following section describes how to tag and push the
Docker image in CodeReady Studio.

Procedure

1. Start CodeReady Studio.

70
CHAPTER 3. DEVELOPING WITH DOCKER

2. Click Window → Show View → Other.


The Show View window appears.

3. Enter Docker in the search field.

4. Select Docker Explorer.

5. Click Open.
The Docker Explorer view appears.

71
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

6. Expand Docker socket → Images.

7. Right-click the image you want to tag.

8. Click Add tag.

The Tag Image window appears.

9. Enter the tag in the New Tag field.


The tag should be in the form of username/image_name:tag_name, where username is your
Docker ID on https://hub.docker.com, image_name is the name of your image, and tag_name
is the version of the image.

72
CHAPTER 3. DEVELOPING WITH DOCKER

10. Click Finish.

11. Right-click the tagged image → Push.

The Push image to Registry window appears.

73
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

12. Select the Registry Account that starts with your Docker ID.

13. 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

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

74
CHAPTER 3. DEVELOPING WITH DOCKER

3. Enter Docker in the search field.

4. Select Docker Explorer.

5. Click Open.
The Docker Explorer view appears.

6. Expand Docker socket → Images.

75
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

7. Right-click images you want to run.

8. Click Run.

The Docker Container settings window appears.

76
CHAPTER 3. DEVELOPING WITH DOCKER

9. Name the container.

10. Clear the Publish all exposed ports to random ports on the host interfacescheck box.

77
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

11. Check the box for 8080 port.

12. Click Finish.


The Console view appears showing the process of starting the image.

13. In the web browser navigate to http://localhost:8080/ to see the image running.

3.2.4. Building images with Dockerfile


You can build an image or create one 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 Section 1.2.2.1, “Creating a Dockerfile” .

Procedure

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

78
CHAPTER 3. DEVELOPING WITH DOCKER

3. Enter Docker in the search field.

4. Select Docker Images.

5. Click Open.
The Docker Images view appears.

6. Click the Build Image icon.

79
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

The Build a Docker Image window appears.

7. Name the image in the format of repo/name:version.

8. Click Browse to locate the Dockerfile.

9. 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

80
CHAPTER 3. DEVELOPING WITH DOCKER

1. Start CodeReady Studio.

2. Click Window → Show View → Other.


The Show View window appears.

3. Enter Docker into the search field.

4. Select Docker Containers.

5. Click Open.
The Docker Containers view appears.

81
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development

You can start, pause, unpause, stop, kill, restart, remove, or refresh the containers by using the panel.

82

You might also like