3

I found very strange behaviour when I build and run docker container. I would like to have container with cassandra and ssh. In my Dockerfile I've got:

RUN echo "deb http://www.apache.org/dist/cassandra/debian 20x main" | sudo tee -a /etc/apt/sources.list
RUN echo "deb-src http://www.apache.org/dist/cassandra/debian 20x main" | sudo tee -a /etc/apt/sources.list
RUN gpg --keyserver pgp.mit.edu --recv-keys 4BD736A82B5C1B00  
RUN apt-key add ~/.gnupg/pubring.gpg  
RUN apt-get update
RUN apt-get -y install cassandra

And then for ssh

RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo '{{ docker_ssh_user }}:{{docker_ssh_password}}' | chpasswd
EXPOSE 22

And I added start script to run everything I want:

USER root
ADD start start
RUN chmod 777 start

CMD ["sh" ,"start"]

And here comes problem. When I have start like this below:

#!/bin/bash
/usr/sbin/sshd -D
/usr/sbin/cassandra -f

SSH is working well. I can do ssh [email protected]. After I log in container I try to run cqlsh to ensure that cassandra is working. But cassandra is not started for some reason and I can't access cqlsh. I've also checked /var/log/cassandra/ but it was empty.

In second scenario I change my start script to this:

#!/bin/bash
/usr/sbin/sshd -D & /usr/sbin/cassandra/ -f

And I again try to connect ssh [email protected] and then when I run cqlsh inside container I have connection to cqlsh.

So I was thinking that ampersand & is doing some voodoo that all works well ? Why I can't run bash staring script with one command below another? Or I'm missing something else??

Thanks for reading && helping.

4
  • I wouldn't know. Very strange indeed. But as this seems very bash-related I added the bash tag. Commented Apr 2, 2014 at 12:21
  • @qkrijger - can I close self answered question and mark as solved ? Commented Apr 2, 2014 at 14:23
  • I don't think so. You should probably answer and accept your own question, based on posts like this on meta: meta.stackexchange.com/questions/93178/… Commented Apr 2, 2014 at 14:44
  • 1
    damn it - I completely missed that you use '&' instead of '&&', which I thought. Check out my article on using supervisor to do this better: blog.trifork.com/2014/03/11/… Commented Apr 2, 2014 at 14:46

1 Answer 1

2

Thanks to my friend linux guru we found the reason of error.

/usr/sbin/sshd -D means that -D : When this option is specified, sshd will not detach and does not become a deamon. This allows easy monitoring of sshd

So in the first script sshd -D was blocking next command to run. In second script I've got & which let sshd -D go background and then cassandra could start. Finally I've got this version of script:

#!/bin/bash
/usr/sbin/sshd
/usr/sbin/cassandra -f
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.