1

Dockerfile:

FROM registry.access.redhat.com/rhel

WORKDIR /usr/src
RUN yum-config-manager --save --setopt=rhel-7-server-rt-beta-rpms.skip_if_unavailable=true

# Install Nginx Repository
RUN yum install -y http://nginx.org/packages/rhel/7/noarch/RPMS/nginx-release-rhel-7-0.el7.ngx.noarch.rpm

# Install 

RUN yum install -y nginx

# Clean up YUM
RUN yum clean all

# Disable Nginx to run on background
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose the HTTP & HTTPS ports
EXPOSE 8080

=================================

Docker build

docker build -t nginxt .

=================================

Docker run

docker run -it -p 8080:8080  nginxt

=================================

[root@ip-20-0-0-86 friday]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                    NAMES
7eaaf772b94a        nginxt              "/bin/bash"         About a minute ago   Up About a minute   0.0.0.0:8080->8080/tcp   elegant_kalam

[root@7eaaf772b94a src]# curl localhost:8080
curl: (7) Failed connect to localhost:8080; Connection refused
Miguel A. C.
  • 1,221
  • 10
  • 12

1 Answers1

1

NGINX Docker image uses port 80 to listen for http connections by default.

If you use EXPOSE 8080 in your Dockerfile you're not setting that port for NGINX to listen on, you're just saying hey my container may listen for connections to port 8080, but not NGINX use 8080 for that you should change the NGINX configuration file.

If you want to use port 8080 you can use the following docker command:

docker run -it -p 8080:80  nginxt

That way 8080 port in your host is forwarded to port 80 of your NGINX container. Also you can change EXPOSE from 8080 to EXPOSE 80 in your Dockerfile.

For your reference:

Miguel A. C.
  • 1,221
  • 10
  • 12