ericj
ericj

Reputation: 2291

How can I extend an image, so that it still works? When can an image be in the from line in a Dockerfile?

I have a sshd Dockerfile. It works. I can ssh to it. I called the image local/c7-sshd.

from centos:7
...
expose 22
cmd ["/usr/sbin/sshd","-D"]

Now I want to extend this image to a httpd image. I have a Dockerfile,

from local/c7-sshd
...
expose 80
cmd ["/usr/sbin/httpd","-D","FOREGROUND"]

When I start a container from this image, httpd runs, but sshd not.

So I do not know when or not an image can be after from in a Dockerfile.

Thanks.

Upvotes: 4

Views: 1610

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46490

You have correctly "extended" the c7-sshd image. The problem is that the CMD instruction in the httpd image replaces the CMD instruction from the c7-sshd image, so only httpd is being started, not sshd. Every image can only have a single CMD instruction which is run when the container is started.

What you need to do is change the CMD instruction so that it launches both httpd and sshd. The best way to do this using a process manager as suggested by Mark O'Connor https://docs.docker.com/articles/using_supervisord/.

Also, it's generally better to do this in a script called from an ENTRYPOINT instruction rather than CMD, so that you can use CMD to provide arguments at run-time to the ENTRYPOINT script.

Finally, do you actually need sshd? You might find using docker exec -it CONTAINER /bin/bash is a better solution.

Upvotes: 5

Related Questions