Implementing DevOps Solutions and Practices using Cisco Platforms

Adding Port 8080 for Intercontainer Communication in a Dockerfile

Question

A DevOps engineer has built a new container and must open port 8080 for intercontainer communication.

Which command must be added in a Dockerfile to accomplish this goal?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

A.

The correct answer is A. EXPOSE 8080.

Explanation:

A Dockerfile is a script that contains a set of instructions for building a Docker image. This image can then be used to create and run containers. One of the common tasks while building a Dockerfile is to expose a port so that other containers or external systems can communicate with the containerized application.

The EXPOSE instruction in a Dockerfile is used to inform Docker that the container will listen on the specified network port at runtime. The EXPOSE instruction does not actually publish the port; it only documents the intent of the containerized application to use that port.

Therefore, to open port 8080 for inter-container communication, the following command should be added to the Dockerfile:

EXPOSE 8080

This instruction tells Docker that the container will listen on port 8080 and any other container or system can access it using the exposed port.

The other options in the answer are not correct:

B. FIREWALL ADD-PORT 8080: This command is not a valid Dockerfile instruction. It is a command that might be used in a firewall or network configuration.

C. PORT 8080: This command is not a valid Dockerfile instruction. It does not expose the port to the host machine or other containers.

D. OPEN PORT 8080: This is not a valid Dockerfile instruction. It is not clear what it is referring to, but it is not a recognized instruction in Dockerfile syntax.