Docker Volume Mapping

Docker Volume Mapping

·

2 min read

In this tutorial, we'll guide you through the process of creating and testing a Docker container with volume mapping on App Server in the Datacenter. The task involves pulling the Nginx image, creating a container, and mapping a host volume to a container volume.

Prerequisites:

  • Access to App Server.

  • Docker installed and running on the host.

  • Basic understanding of Docker containerization.

Task Overview:

The task requires creating a Docker container named official from the Nginx image and mapping the host volume /opt/dba to the container volume /tmp. Additionally, a file named sample.txt located under /tmp on the host needs to be copied to /opt/dba within the container.

1. SSH into the Host Server:

First, establish an SSH connection to App Server 1 where you'll perform the Docker tasks.

ssh user@app_server_ip

Replace user with your username and app_server_ip with the IP address of App Server.

2. Pull the Nginx Image:

Pull the Nginx image from Docker Hub using the following command:

docker pull nginx

This command fetches the latest version of the Nginx image from Docker Hub.

3. Create and Run the Docker Container:

Create a Docker container named official from the Nginx image and map the host volume /opt/dba to the container volume /tmp using the following command:

docker container run -d --name official -v /opt/dba:/tmp nginx

This command starts a Docker container named official in detached mode (-d), maps the host volume /opt/dba to the container volume /tmp, and uses the Nginx image.

4. Copy the File to the Host Volume:

Copy the sample.txt file located under /tmp on the host to /opt/dba using the following command:

cp /tmp/sample.txt /opt/dba/

This command copies the sample.txt file from the host to the mapped volume /opt/dba within the container.

Conclusion:

In this tutorial, you learned how to create and test a Docker container with volume mapping on App Server. By following the provided steps, you can efficiently manage data persistence and transfer between the host and containers using Docker volumes, facilitating easier application deployment and management in containerized environments.