RUN command not called in Dockerfile

Here is my Dockerfile:

# Pull base image (Ubuntu)
FROM dockerfile/python

# Install socat
RUN \
  cd /opt && \
  wget http://www.dest-unreach.org/socat/download/socat-1.7.2.4.tar.gz && \
  tar xvzf socat-1.7.2.4.tar.gz && \
  rm -f socat-1.7.2.4.tar.gz && \
  cd socat-1.7.2.4 && \
  ./configure && \
  make && \
  make install

RUN \
  start-stop-daemon --quiet --oknodo --start --pidfile /run/my.pid --background --make-pidfile \
  --exec /opt/socat-1.7.2.4/socat PTY,link=/dev/ttyMY,echo=0,raw,unlink-close=0 \
  TCP-LISTEN:9334,reuseaddr,fork

# Define working directory.
WORKDIR /data

# Define default command.
CMD ["bash"]

      

I build an image from this Dockerfile and run it like this:

docker run -d -t -i myaccount/socat_test

      

After that, I go into the container and check if the socat daemon is running. But this is not the case. I just started playing with docker. I don't understand the concept of Dockerfile? I expect docker to execute the socat command when starting the container.

+3


source to share


1 answer


You are misleading RUN

and CMD

. The command RUN

is for creating a docker container as you did right with the first one. The second command will also run when the container is created, but not when it runs. If you want to execute commands when starting a docker container, you must use the command CMD

.



More details can be found in the Dockerfile link . For example, you can also use ENTRYPOINT

instead of CMD

.

+4


source







All Articles