Skip to main content

Lab 002: Run a Docker Container



Requirements

Nautilus DevOps team is testing some applications deployment on some of the application servers. They need to deploy a nginx container on Application Server 3. Please complete the task as per details given below:

On Application Server 3 create a container named nginx_3 using image nginx with alpine tag and make sure container is in running state.


Note

The Requirements section is kept as the source task statement. The procedure below uses a single direct docker run workflow and keeps the verification separate.

Prerequisites

  • You can SSH to Application Server 3 and switch to a privileged shell.
  • Docker is installed and the daemon is available on the host.
  • The server can pull the nginx:alpine image from the registry.

Steps

Log-in to the specified app server.

sshpass -p '*********' ssh -o StrictHostKeyChecking=no banner@172.16.238.12
sudo su

As best practice, always check the existing containers and images on the machien first.

docker ps -a
docker images

Create the container. This can be done through a YAML file, but since it's a fairly simple container, we can just run the CLI command with parameters.

docker run -d --name nginx_3 -p 8080:80 nginx:alpine

Verify that the image is pulled down and that the container is running.

[root@stapp03 banner]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
nginx alpine 1e415454686a 10 days ago 40.7MB
[root@stapp03 banner]# docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
905c8c922a78 nginx:alpine "/docker-entrypoint.…" 13 seconds ago Up 11 seconds 0.0.0.0:8080->80/tcp nginx_3

As an additional test, we could also run a curl to the loclahost via port 8080. It shold return a "200 OK" message.

[root@stapp03 banner]# curl -I localhost:8080

HTTP/1.1 200 OK
Server: nginx/1.23.3
Date: Sat, 24 Dec 2022 03:43:57 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 13 Dec 2022 18:23:05 GMT
Connection: keep-alive
ETag: "6398c309-267"
Accept-Ranges: bytes

Verification

  • Confirm the image is present with docker images | grep nginx.
  • Confirm the container named nginx_3 is running with docker ps -a | grep nginx_3.
  • Optionally confirm the published port responds with curl -I localhost:8080 and expect an HTTP 200 OK response.

Resources