Incorrect exercise (Exercise: Creating Custom Image from a Do) ht

Given solition just do nothing:
[user@linuxacademy:custom/]$ vi Dockerfile

(Output) NOTE: This is one example of what this file needs to contain, yours may differ slightly

# Dockerfile that modifies centos:centos6 to update, include Apache Web

# Server and OpenSSH Server, exposing the appropriate ports

FROM centos:centos6

MAINTAINER User Name <username@domain.com>

# Update the server OS

RUN yum -y upgrade

# Install Apache Web Server

RUN yum -y install httpd

# Install OpenSSH-Server

RUN yum -y install openssh-server

# Expose the SSH and Web Ports for attachment

EXPOSE 22 80

(Output)


As we can see here docker will expose port, but there are no any CMD or ENTRYPOINT directives to start openssh-server and apache.


So, given exaple will expose ports, telnet will work, because docker open these port. But in general sshd and apache will not work.


I cannot find how to start 2 services without control of init system. Please help. I tried to do something like this:


CMD ["/usr/sbin/sshd", "-D"; "/usr/sbin/apachectl","-DFOREGROUND"]
, but it does not work. Only apache works and no sshd and ports exposed.
My dockerfile:

FROM centos:6
MAINTAINER lolka <lol@mail.ru>
RUN yum update -y && rm -rf /var/cache/yum
RUN yum install -y httpd openssh-server
CMD ["/usr/sbin/sshd", "-D"; "/usr/sbin/apachectl","-DFOREGROUND"]
EXPOSE 22 80

  • post-author-pic
    Terrence C
    10-08-2018

    You could add the startup commands to a profile file (profile itself or .bashrc or the like) so that if you instantiate a container and connect to a shell it starts the service(s).


    However, you would probably want to create another image based on this one and add an ENTRYPOINT to run your service (standard method) or redo the image you are using in a new Dockerfile adding the ENTRYPOINT at the end.

Looking For Team Training?

Learn More