This is my Dockerfile:
FROM centos:7
MAINTAINER rlabs
LABEL Remarks="This is a dockerfile example for Centos system"
# Install Java
RUN yum update -y \
&& yum install java-1.8.0-openjdk -y \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& yum -y install httpd httpd-tools
# Install Python
RUN yum install python3 -y \
&& pip3 install --upgrade pip setuptools wheel \
&& if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi \
&& if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi \
&& yum clean all \
&& rm -rf /var/cache/yum
# load generic RPMs
RUN pip3 install boto3 \
&& yum -y install sudo \
&& yum -y install git \
&& yum -y install gem \
&& yum -y install wget \
&& yum -y install gcc
RUN yum -y install unzip \
&& yum -y install net-tools \
&& yum -y install tcpdump
# add local files to image
COPY aws/aws_config_template /root/.aws/config
COPY aws/aws_credentials_template /root/.aws/credentials
RUN useradd myuser
RUN ln -s /root/.aws /home/myuser
COPY mydir /site/mydir
RUN mkdir /site/log
COPY systemctl.py /usr/bin/systemctl
RUN chmod a+x /usr/bin/systemctl
EXPOSE 80
EXPOSE 8000
EXPOSE 8001
RUN chown -R 1000:1000 /site
USER myuser
WORKDIR /site/mydir
When I add this in Dockerfile:
ENTRYPOINT["ping"]
CMD["google.com]
and then run command:
docker run -d -p 8001:8001 myimage
Docker container runs fine. I am able to ssh into my container and run one shell script which runs the jar file and expose the 8001 port.
But if I try to run same shell script by adding CMD like this in Dockerfile
CMD["sh","/site/mydire/myfile.sh"]
and remove ENTRYPOINT from the Dockerfile and then run command:
docker run -d -p 8001:8001 myimage
nothing happens. On doing docker ps, container spins up for a second or two and then gets deleted automatically.If i do docker ps again, nothing shows up. Am I missing something here?