The Nautilus DevOps team is testing applications containerization, which is supposed to be migrated on docker container-based environments soon. In today's stand-up meeting one of the team members has been assigned a task to create and test a docker container with certain requirements. Below are more details:

a. On App Server 1 in Stratos DC pull nginx image (preferably latest tag but others should work too).

b. Create a new container with name news from the image you just pulled.

c. Map the host volume /opt/itadmin with container volume /tmp. There is an sample.txt file present on same server under /tmp; copy that file to /opt/itadmin. Also please keep the container in running state.

Connect to App Server 1

ssh tony@stapp01 sudo -i 

Password for tony: Ir0nM@n

Pull the nginx Image

docker pull nginx:latest 

The image was pulled successfully with digest sha256:4c41e2d0a3a55b325ed572cd0200bdb72af1433c3daa2bca6ef8eea68ce504a2.

Verify the image:

docker images | grep nginx 

Output:

nginx latest 14700d2ee6c4 5 days ago 163MB 

Verify and Copy the Sample File

Confirm the sample file exists:

ls -la /tmp/sample.txt 

Output:

-rw-r--r-- 1 root root 23 Oct 27 11:05 /tmp/sample.txt 

Create the target directory and copy the file:

mkdir -p /opt/itadmin cp /tmp/sample.txt /opt/itadmin/ 

Verify the copy:

ls -la /opt/itadmin/ 

Output:

-rw-r--r-- 1 root root 23 Oct 27 11:09 sample.txt 

Create the Container with Volume Mapping

docker run -d --name news -v /opt/itadmin:/tmp nginx:latest 

The container was created with ID f6d16445bdf5.

Verify the Container is Running

docker ps | grep news 

Output:

f6d16445bdf5 nginx:latest "/docker-entrypoint.…" 16 seconds ago Up 15 seconds 80/tcp news 

The container news is running.

Verify the Volume Mapping

docker inspect news --format='{{range .Mounts}}{{.Source}} -> {{.Destination}}{{end}}' 

Output:

/opt/itadmin -> /tmp 

The host /opt/itadmin is correctly mapped to container /tmp.

Verify the File Inside the Container

docker exec news ls -la /tmp/sample.txt 

Output:

-rw-r--r-- 1 root root 23 Oct 27 11:09 /tmp/sample.txt 

The file is accessible inside the container through the volume mount.

Complete Command Sequence

ssh tony@stapp01 sudo -i docker pull nginx:latest mkdir -p /opt/itadmin cp /tmp/sample.txt /opt/itadmin/ docker run -d --name news -v /opt/itadmin:/tmp nginx:latest docker ps | grep news docker inspect news --format='{{range .Mounts}}{{.Source}} -> {{.Destination}}{{end}}' docker exec news ls -la /tmp/sample.txt