I'm trying to create a Dockerfile. I'm new to Docker. I'm creating this Dockerfile which shall start rabbitmq, ftp server and elasticsearch server in one instance. I have created the file like this :
# Pull base image
FROM alpine:latest
MAINTAINER Harshit Prasad
# define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
# Expose the web interface ports
# 2121: ftp, a FTP server to be used for mass data / file storage
# 5672: rabbitmq, a rabbitmq message queue server to be used for global messages, queues and stacks
# 9300: elastic, an elasticsearch server or main cluster address for global database storage
EXPOSE 2121 5672 9300
# install Java
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install -y oracle-java8-installer && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer
# install apache ftp server 1.1.0
RUN wget http://www-eu.apache.org/dist/mina/ftpserver/1.1.0/dist/apache-ftpserver-1.1.0.tar.gz
RUN tar xfz apache-ftpserver-1.1.0.tar.gz
# run ftp server
RUN cd apache-ftpserver-1.1.0 bin/ftpd.sh res/conf/ftpd-typical.xml
# install RabbitMQ server
RUN wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-generic-unix-3.6.6.tar.xz
RUN tar xf rabbitmq-server-generic-unix-3.6.6.tar.xz
# run the RabbitMQ server
RUN cd rabbitmq_server-3.6.6/sbin/rabbitmq-server
# install the management plugin to be able to use a web interface
RUN cd rabbitmq_server-3.6.6/sbin/rabbitmq-plugins enable rabbitmq_management
# install erlang programming language. RabbitMQ is written in erlang.
RUN apt-get install erlang
# elasticsearch service here
# set current working directory to yacy_grid_mcp
RUN git clone https://github.com/yacy/yacy_grid_mcp.git
WORKDIR /yacy_grid_mcp
I wanted to know if I'm creating Dockerfile correctly. It would be great if anyone can help me out. Also please let me know how should I proceed for adding elasticsearch service. Thanks in advance!
you shouldn't.
A docker container is not a full virtual machine to run a complete stack of application instances and services.
Docker is application virtualization. That means a single container runs a single process.
In your case, you need 3 containers. One for RabbitMQ, one for your FTP service, one for elastic search.
You'll probably want to use named data volumes to share the file system between the FTP service and whatever reads it, as well.
Once you have all three containers working, you can use docker-compose to simplify running them together.
When you build your container, RUN will execute your command, then save the filesystem and exit. So when you run you container, your service is not running. You should use CMD to execute a single command.
You should go around the docker documentation, you will find that running multiples services like this is not the way to do it, you should have one container for each service.
However, I agree that sometimes, it can be useful to have multiples services (not your case I think), you can have a look at https://docs.docker.com/engine/admin/multi-service_container/, you will find some ways to do it