You are on page 1of 4

Experiment No. 2.

3
Student Name: Biki Kumar Rai UID: 22MCC20118
Branch: MCA - CCD Section/Group: 22MCD-2/ Grp B
Semester: III Date of Performance: 26th Sep, 23
Subject Name: Docker Lab Subject Code: 22CAH-742

1. Aim/Overview of the practical:


Understanding the Docker file for Customizing images

2. Code/Steps for experiment:


Step 1: Create a Docker Volume:
Docker volumes are used to persist data outside of the container. Create a volume using the
following command: docker volume create my_volume

Step 2: Run an Ubuntu Container with the Volume Mounted:


Use the docker run command to start an Ubuntu container with the volume mounted:
code
docker run -it --name my_container -v my_volume:/data ubuntu

Step 3: Access the Volume Inside the Container:


Once inside the container, you can navigate to the mounted volume using the /data directory:
cd /data

Step 4: Exit the Container:


When you're done working inside the container, you can exit by typing exit.
Step 5: Stop and Remove the Container:
docker stop my_container
docker rm my_container

Step 6: Verify Data Persistence:


Start a new container and mount the volume again. Verify that the data you stored in the
volume is still accessible:

Bind Mount

Step 1: Create a Directory on the Host:


Create a directory on your host machine where you want to store the data. For example:
mkdir ~/my_data

Step 2: Run an Ubuntu Container with Bind Mount:


Start an Ubuntu container, specifying the bind mount:
docker run -it --name my_container -v ~/my_data:/data ubuntu

Step 3: Access the Bind Mount Inside the Container:


Once inside the container, you can navigate to the /data directory to access the files on the
host.
cd /data

Any changes made in this directory will be reflected on the host machine.
Step 4: Exit the Container:
When you're done working inside the container, you can exit by typing exit.

Step 5: Stop and Remove the Container:


Stop and remove the container when you're finished:
docker stop my_container
docker rm my_container

Step 6: Verify Data Persistence:


Check the ~/my_data directory on your host machine. The data you created or modified
inside the container should be present in this directory.

tmpfs mount
Step 1: Start an Ubuntu container with a tmpfs mount:
docker run -it --name my_container --tmpfs /data ubuntu

Step 2: Access the tmpfs Mount Inside the Container:


cd /data

Step 3: Any changes made in this directory will be stored in the host's memory
temporarily.

Step 4: Exit the Container:


Step 5: Stop the Container:
docker stop my_container

Step 6: Verify Temporary Data Persistence:


Restart the same container:
docker start -i my_container

Step 7: Enter the container and check if the file or directory you created in the /data
directory still exists:

cd /data
ls

Step 8: Stop and Remove the Container:


docker stop my_container
docker rm my_container

You might also like