Post

Containers - Image Versions

Lab assignment for creating a container using containerd and docker with different versions.

Containers - Image Versions

Prerequisites

  • Docker

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!!! Version 1</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
    
     docker build -t mywebsite:v1 ./mywebsite
    
  7. Verify if the images has been created

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

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

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

    1
    
    /mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe http://localhost:8080/
    
  11. Update the index.html with some changes

    1
    
    echo "<h1>Welcome to Containers!</h1> Version 2" > ./mywebsite/index.html   
    
  12. Build a new image which will include the changes

    1
    
    docker build -t mywebsite:v2 ./mywebsite
    
  13. Run the container with the new image named v2

    1
    
    docker run -d -p 8082:80 --name container-demo mywebsite:v2
    
  14. Browse the website and confirm that the changes are reflected.

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