Module 5: Assignment - 1
Tasks To Be Performed:
- Install a Docker using VM
- Pull hshar/webapp (webapp) repository
- Create a new file in this repository
Step 1: Install Docker on a Virtual Machine
-
I Create a Linux VM:
-
Will use the VM from Assignment 5: Module 4
-
-
I Install Docker Using
docker.io
: ^f947ef- I run the following commands to update the package index and install Docker from the Ubuntu repositories:
sudo apt-get update
sudo apt-get install docker.io
- After the installation, I start and enable Docker to ensure it’s running and set to start on boot:
sudo systemctl start docker
sudo systemctl enable docker
- I verify Installation
sudo docker --version
- I run the following commands to update the package index and install Docker from the Ubuntu repositories:
Step 2: Pull the hshar/webapp
Docker Repository
- I Pull the Docker Image:
- I use the Docker command to pull the
hshar/webapp
image from Docker Hub:sudo docker pull hshar/webapp
- I use the Docker command to pull the
Step 3: Create a New File in the Repository
-
I Run a Container from the Pulled Image:
- I start a Docker container using the
hshar/webapp
image:sudo docker run -dit --name webapp-container hshar/webapp
- I start a Docker container using the
-
I Access the Container’s Shell:
- I access the shell of the running container:
sudo docker exec -it webapp-container bash
- I access the shell of the running container:
-
I Create a New File in the Container:
- Inside the container, I navigate to the desired directory.
- I create a new file
touch newfile.txt
Step 4: Commit the Changes to Create a New Docker Image
-
Commit the Container to a New Image:
- Use the
docker commit
command to create a new image from the container’s current state. - The syntax is
docker commit [CONTAINER_ID] [new_image_name]:[tag]
.
- Use the
-
Verify the New Image:
- Use
docker images
to list all images and verify that your new image (mynewimage:latest
) is there.
- Use
azureuser@VMCustomImage:~$ sudo docker commit f88acb1dcab07b1ae0 hshar/webapp_updated:latest
sha256:5d9250a92e2766f6b591a7ab647888a836ef9da9ea779a098abcce830ee2e284
azureuser@VMCustomImage:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hshar/webapp_updated latest 5d9250a92e27 8 seconds ago 303MB
<none> <none> 853e35c08c74 30 seconds ago 303MB
hshar/webapp latest 0cbc1f535ed8 4 years ago 303MB
azureuser@VMCustomImage:~$