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.
Create an index.html file for the website.
1
mkdir mywebsite
Add content to the index.html file
1
echo "<h1>Welcome to Containers!!! Version 1</h1>" > ./mywebsite/index.html
Verify the content of the index.html file
1
cat ./mywebsite/index.html
Create a Dockerfile to create an container
1
touch ./mywebsite/Dockerfile
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
Build an image with nerdctl using the Dockerfile
1
docker build -t mywebsite:v1 ./mywebsite
Verify if the images has been created
1
docker images
Run the Container using the image created in the previous step
1
docker run -d -p 8081:80 --name container-demo mywebsite:v1
Verify if the container is up and running
1
docker ps
Browse the Website using the port 8080
1
/mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe http://localhost:8080/
Update the index.html with some changes
1
echo "<h1>Welcome to Containers!</h1> Version 2" > ./mywebsite/index.html
Build a new image which will include the changes
1
docker build -t mywebsite:v2 ./mywebsite
Run the container with the new image named v2
1
docker run -d -p 8082:80 --name container-demo mywebsite:v2
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.