Dockerfile – CMD does not run the shell script

Ok just learning about creating a Dockerfile and my understanding (which is probably wrong) is that the CMD command should be able to run a shell script from within the container once it is placed there.

I am just trying it out with a vanilla apache2 install

  • How to fix Docker's “Error pulling image…too many redirects” failures while pulling images from registry?
  • Gitlab CI Runner Docker Executor Expose Ports
  • Unable to push my docker to Bluemix - Login error
  • Not able to access Flask Web application running inside a Docker container
  • Version of Ubuntu being used in a docker container
  • how to reach docker containers with network host from w10 pc?
  • Dockerfile

    FROM ubuntu:latest
    ADD /Scripts/
    RUN chmod +x /Scripts/
    CMD [/Scripts/]
    RUN echo "Hope this worked!"

    I have also tried this:

    CMD ["/Scripts/"]

    When I use the RUN command it works (without the [ and ])

    So I am a bit lost what the CMD is suppose to do.

    I followed the instructions from
    and read through the docker docs as well.

    How am I using the CMD wrong and how should I use it in this scenario?

  • Dynamic Scalable and adaptive architecture
  • Dockerfile expose port for node.js image
  • Docker inside Docker (without command line) [duplicate]
  • Docker orchestration
  • Docker receiving multicast traffic
  • how to check syslog for ubuntu docker
  • One Solution collect form web for “Dockerfile – CMD does not run the shell script”

    • RUN is executed while you are building an image. This is usually used to install things or perform modifications in the resulting image.
    • CMD is executed when the container is started. Use this to e.g. start applications.

    Also check the docs

    The main purpose of a CMD is to provide defaults for an executing
    container. These defaults can include an executable, or they can omit
    the executable, in which case you must specify an ENTRYPOINT
    instruction as well.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.