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.
Create an index.html file for the website.
1
mkdir mywebsite
Add content to the index.html file
1
echo "<h1>Welcome to Containers!</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
nerdctl build -t mywebsite-nerd:latest ./mywebsite
Verify if the images has been created
1
nerdctl images
Run the Container using the image created in the previous step
1
nerdctl run -d -p 8081:80 --name container-demo mywebsite-nerd:latest
Verify if the container is up and running
1
nerdctl ps
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.