How to add a Maven project to an Ubuntu image in Docker

35 Views Asked by At

I have built an Ubuntu image with the Dockerfile as follows:

FROM ubuntu:latest

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y openjdk-8-jdk dub wget rsync nano sudo

RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

RUN wget https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz && \
    tar -xvf kafka_2.13-3.7.0.tgz && \
    mkdir -p /home/servidor-kafka/kafka && \
    rsync -av --remove-source-files kafka_2.13-3.7.0/ /home/servidor-kafka/kafka/ && \
    rm kafka_2.13-3.7.0.tgz

RUN wget https://downloads.apache.org/zookeeper/zookeeper-3.7.2/apache-zookeeper-3.7.2-bin.tar.gz && \
    tar -xvf apache-zookeeper-3.7.2-bin.tar.gz && \
    mkdir -p /home/servidor-kafka/zookeeper && \
    rsync -av --remove-source-files apache-zookeeper-3.7.2-bin/ /home/servidor-kafka/zookeeper/ && \
    rm apache-zookeeper-3.7.2-bin.tar.gz

# Change ownership of Kafka and Zookeeper directories to the docker user
RUN chown -R docker:docker /home/servidor-kafka/kafka && \
    chown -R docker:docker /home/servidor-kafka/zookeeper

WORKDIR /home/servidor-kafka/kafka

EXPOSE 9092 2181
USER docker

CMD ["/bin/bash"]

And now I am looking to create now a Maven project in this image. I was thinking about creating the Maven project and moving it to the Ubuntu image so adding these lines at the end of the Dockerfile should work:

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y openjdk-8-jdk maven wget rsync nano sudo

and

COPY ./maven-project /home/servidor-kafka/maven-project

RUN mvn clean install

I have seen many other ways to add a Maven project to a Docker image but I wanted to receive some feedback from you guys for my specific case. Do you think this is the best way to do it? Thank you.

0

There are 0 best solutions below