The Nautilus DevOps team is testing application containerization, with plans to migrate applications to Docker container-based environments soon. In today's stand-up meeting, one of the team members has been assigned the task to:
- Pull the
nginx
Docker image (preferably the latest tag) on App Server 3 in the Stratos Datacenter. - Create a new container named
official
from the pulled image. - Map the host volume
/opt/itadmin
to the container volume/usr/src/
. - Copy a file named
sample.txt
from/tmp
to/opt/itadmin
on the host. - Ensure the container is in a running state.
-
Pull the Docker Image
Start by pulling the
nginx
Docker image. It is preferable to use thelatest
tag, but other tags will work as well.docker pull nginx:latest
This command downloads the
nginx:latest
image from Docker Hub to App Server 3. -
Create and Run the Container
Create a new container named
official
using the pullednginx:latest
image. Bind the host volume/opt/itadmin
to the container volume/usr/src/
to ensure file sharing between the host and the container.docker run -it -d --name official -v /opt/itadmin:/usr/src/ nginx:latest
-it
runs the container in interactive mode with a terminal attached.-d
runs the container in detached mode (in the background).--name official
assigns the nameofficial
to the container.-v /opt/itadmin:/usr/src/
mounts the host directory/opt/itadmin
to the container directory/usr/src/
.
-
Verify Volume Binding
To check whether the volume binding was successful, inspect the container’s configuration. Look for the volume mounts section in the container details.
docker inspect official
Example output (relevant part):
"Mounts": [ { "Type": "bind", "Source": "/opt/itadmin", "Destination": "/usr/src", "Mode": "", "RW": true, "Propagation": "rprivate" } ]
This output confirms that
/opt/itadmin
on the host is correctly bound to/usr/src
in the container. -
Copy the File to the Host Volume
Move the
sample.txt
file from/tmp
to/opt/itadmin
on the host. This file will be accessible from within the container through the mounted volume.mv /tmp/sample.txt /opt/itadmin/
-
Verify File Access in the Container
To ensure that the
sample.txt
file is accessible within the container, execute a shell in theofficial
container and check the file’s contents.docker exec -it official /bin/bash
Inside the container, use the following command to view the file:
cat /usr/src/sample.txt
Expected output:
This is a sample file!!