Hello World Example
This tutorial will demonstrate how to get started with Rancher Desktop by pushing an app to a local Kubernetes cluster.
Rancher Desktop works with two container engines, containerd and Moby, the open-sourced components of the Docker ecosystem. For nerdctl, use the containerd runtime. For docker, use the dockerd(moby) runtime.
Example#1 - Build Image & Run Container
Create a folder
mkdir hello-world
cd hello-world
Create a blank Dockerfile
On Windows, Create a blank file named Dockerfile
On Linux, You can use below command to create a blank Dockerfile
vi Dockerfile
Populate the Dockerfile with the command below
FROM alpine
CMD ["echo", "Hello World!!"]
Build and run the image for verification purposes
- nerdctl
- docker
nerdctl build --tag helloworld:v1.0 .
nerdctl images | grep helloworld
nerdctl run --rm helloworld:v1.0
# Remove the image
nerdctl rmi helloworld:v1.0
docker build --tag helloworld:v1.0 .
docker images | grep helloworld
docker run --rm helloworld:v1.0
# Remove the image
docker rmi helloworld:v1.0
Example#2 - Build Image & Deploy Container to Kubernetes
Make sure that you switch the Container Runtime setting in the Kubernetes Settings panel to either dockerd or containerd as needed.
Create a folder and add a sample index.html file as follows
mkdir nginx
cd nginx
echo "<h1>Hello World from NGINX!!</h1>" > index.html
Create a blank Dockerfile
On Windows, Create a blank file named Dockerfile
On Linux, You can use below command to create a blank Dockerfile
vi Dockerfile
Populate the Dockerfile with the command below
FROM nginx:alpine
COPY ./index.html /usr/share/nginx/html