Help Running A Container

Hello,

I’m fairly new to docker/containers. I have the below Dockerfile [1]. Ultimately, I’m trying to run a specific version of Apache Httpd (contained within a zip file). The image builds without any issue. However, I can’t get the container to continuously run. To run, I using the following:

docker run -it <port-mappings> <my-image-name>

The container literally starts for a split second and exits.

Thanks for your help!!

[1]

FROM centos:7

# update OS
RUN yum -y update && \
yum -y install sudo unzip elinks krb5-workstation mailcap && \
yum clean all

RUN groupadd -g 48 -r apache
RUN /usr/sbin/useradd -c "Apache" -u 48 -g apache -s /sbin/nologin -r apache

RUN mkdir -p /opt/httpd

WORKDIR /opt/httpd

ADD jbcs-httpd24-httpd-2.4.51-RHEL7-x86_64.zip /opt/httpd

RUN unzip jbcs-httpd24-httpd-2.4.51-RHEL7-x86_64.zip

RUN cd jbcs-httpd24-2.4/httpd/

RUN chown -R apache:apache *

WORKDIR /opt/httpd/jbcs-httpd24-2.4/httpd/

RUN pwd

RUN  ./.postinstall

EXPOSE 80 443 6666

RUN pwd

CMD ["/opt/httpd/jbcs-httpd24-2.4/httpd/sbin/apachectl", "-D", "FOREGROUND"]

I was able to figure it out. Evidently the “RUN pwd” statement prior to the CMD statement was the issue. After removing it, the Httpd container runs as expected.

1 Like

Interesting. RUN pwd just shows the current working directory when docker build runs. It doesn’t effect how the container runs. At least it shouldn’t. Are you sure this was the solution and you didn’t change anything else to make it work?

By the way, do you know that this line does nothing, because each RUN instruction starts a new container to create a new filesystem layer?

It is like @rimelek says. Some instructions have no effect and the image can be optimized.

The ADD instruction already extracts archives + you can chown the files right away. An optimized version of your Dockerfile could look like this.

FROM centos:7

# update OS
RUN yum -y update && \
  yum -y install sudo unzip elinks krb5-workstation mailcap && \
  yum clean all

RUN groupadd -g 48 -r apache && \
    /usr/sbin/useradd -c "Apache" -u 48 -g apache -s /sbin/nologin -r apache

ADD --chown=apache:apache jbcs-httpd24-httpd-2.4.51-RHEL7-x86_64.zip /opt/httpd

WORKDIR /opt/httpd/jbcs-httpd24-2.4/httpd/

RUN  ./.postinstall

EXPOSE 80 443 6666

CMD ["/opt/httpd/jbcs-httpd24-2.4/httpd/sbin/apachectl", "-D", "FOREGROUND"]

I couldn’t test the image build, as I have no jboss account on my private laptop.

Thanks guys for your help. Maybe I was doing something wrong on my end. The original/pasted dockerfile seems to now run without issue. @meyay thanks for a more optimized version (I’m still learning).