3

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Can you help me translating my RUN start-stop-daemon command to CMD? I am a bit confused with the syntax.
Hmm maybe I should but it inside a startup script. But I wished I could wrap this inside the Dockerfile. I will open another question on that topic.
Containers are not full VM's. start-stop-daemon is not the right way.
@artworkadシ: Just make a list with the "words" of the command separated. As if you called String.split on it. CMD ["start-stop-daemon", "--quiet", ...]. You should consider running your program in foreground as @user2105103 suggested though. Docker's -d takes care of the daemonizing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.