Skip to main content

TASK 97: Docker Ports Mapping



Requirements

The Nautilus DevOps team is planning to host an application on a nginx-based container. There are number of tickets already been created for similar tasks. One of the tickets has been assigned to set up a nginx container on Application Server 1 in Stratos Datacenter. Please perform the task as per details mentioned below:

a. Pull nginx:stable docker image on Application Server 1.

b. Create a container named ecommerce using the image you pulled.

c. Map host port 6100 to container port 80. Please keep the container in running state.


Note

The Requirements section stays unchanged. The implementation below uses a single docker run command with explicit port publishing and then validates the mapping.

Prerequisites

  • You can SSH to Application Server 1 and switch to a privileged shell.
  • Docker is installed and the host can pull the nginx:stable image.
  • Host port 6100 is available for publishing.

Steps

Login to the specified app server. Replace the "*******" with the user's password. For the server credentials, check out the Project Nautilus documentation.

sshpass -p '*******' ssh -o StrictHostKeyChecking=no tony@172.16.238.10
sudo su -

As best practice, check the existing resources.

[root@stapp01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

Pull down the requiremed NGINX image.

docker pull nginx:stable

Run the container based on the requirements.

docker container run -d --name ecommerce -p 6100:80 nginx:stable

Check if the container is running.

[root@stapp01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0852f8ac47a nginx:stable "/docker-entrypoint.…" 14 seconds ago Up 10 seconds 0.0.0.0:6100->80/tcp ecommerce

Verify the NGINX application by running a simple curl.

[root@stapp01 ~]# curl -I http://localhost:6100

HTTP/1.1 200 OK
Server: nginx/1.22.1
Date: Sat, 04 Feb 2023 01:24:23 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Wed, 19 Oct 2022 08:02:20 GMT
Connection: keep-alive
ETag: "634faf0c-267"
Accept-Ranges: bytes

Verification

  • Confirm the container ecommerce is running with docker ps | grep ecommerce.
  • Confirm the port mapping is 6100:80 with docker ps or docker inspect ecommerce.
  • Confirm the application responds with curl -I http://localhost:6100 and expect an HTTP 200 OK response.

Resources