Post

Containers - Using ContainerD & Nerdctl

Lab assignment for creating a container using containerd and nerdctl.

Containers - Using ContainerD & Nerdctl

Prerequisites

  • containerd
  • nerdctl

Assignment

  • Lets start by creating a container for running a website in a container using containerd and nerdctl.
  1. Create an index.html file for the website.

    1
    
     mkdir mywebsite
    
  2. Add content to the index.html file

    1
    
     echo "<h1>Welcome to Containers!</h1>" > ./mywebsite/index.html   
    
  3. Verify the content of the index.html file

    1
    
     cat ./mywebsite/index.html
    
  4. Create a Dockerfile to create an container

    1
    
     touch  ./mywebsite/Dockerfile
    
  5. Add the below steps in the Dockerfile

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
     cat <<EOF > ./mywebsite/Dockerfile
     # Use a lightweight web server base image
     FROM nginx:alpine
    
     # Copy the HTML file to the web server's root directory
     COPY index.html /usr/share/nginx/html/index.html
    
     # Expose the web server's port
     EXPOSE 80
     EOF
    
  6. Build an image with nerdctl using the Dockerfile

    1
    
     nerdctl build -t mywebsite-nerd:latest ./mywebsite
    
  7. Verify if the images has been created

    1
    
     nerdctl images
    
  8. Run the Container using the image created in the previous step

    1
    
     nerdctl run -d -p 8081:80 --name container-demo mywebsite-nerd:latest
    
  9. Verify if the container is up and running

    1
    
     nerdctl ps
    
  10. Browse the Website using the port 8080

    1
    
    /mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe http://localhost:8080/
    
This post is licensed under CC BY 4.0 by the author.