DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

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 this I login into the container and check if socat daemon is running. But it is not. I just started playing around with docker. Am I misunderstanding the concept of Dockerfile? I would expect docker to run the socat command when the container starts.

Upvotes: 3

Views: 4095

Answers (1)

Noctua
Noctua

Reputation: 5208

You are confusing RUN and CMD. The RUN command is meant to build up the docker container, as you correctly did with the first one. The second command will also executed when building the container, but not when running it. If you want to execute commands when the docker container is started, you ought to use the CMD command.

More information can be found in the Dockerfile reference. For instance, you could also use ENTRYPOINT in stead of CMD.

Upvotes: 5

Related Questions