Reduce docker images size with reduced set of java modules
[integration/packaging.git] / odl-docker / Dockerfile
1 # SPDX-License-Identifier: EPL-1.0
2 ##############################################################################
3 # Copyright (c) 2021 The Linux Foundation and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Eclipse Public License v1.0
7 # which accompanies this distribution, and is available at
8 # http://www.eclipse.org/legal/epl-v10.html
9 ##############################################################################
10
11 FROM openjdk:11-jdk-slim AS stage0
12
13 USER root
14
15 ARG ODL_VERSION
16
17 RUN set -eux \
18     && cd $HOME \
19     && apt-get update \
20     && apt-get install -y curl \
21     && rm -rf /var/lib/apt/lists/* \
22     && mkdir -p /opt/opendaylight \
23     && jlink --add-modules java.base,java.compiler,java.desktop,java.logging,java.management,java.naming,java.rmi,java.security.sasl,java.sql,java.xml,jdk.jfr,jdk.naming.rmi,jdk.xml.dom,jdk.unsupported --output /opt/openjdk-11 \
24     && rm -rf /usr/local/openjdk-11 
25
26 COPY start_docker.sh /opt/opendaylight
27
28 FROM scratch as stage1
29
30 ENV JAVA_HOME /opt/openjdk-11
31 ENV PATH $PATH:$JAVA_HOME/bin
32 ENV FEATURES odl-restconf-all
33
34 WORKDIR /opt/opendaylight
35
36 ARG ODL_VERSION
37
38 COPY --from=stage0 / /
39
40 RUN set -eux \
41     && curl https://nexus.opendaylight.org/content/repositories/opendaylight.release/org/opendaylight/integration/opendaylight/${ODL_VERSION}/opendaylight-${ODL_VERSION}.tar.gz | tar zxf - -C /opt/opendaylight/ --strip-components 1 \
42     && groupadd -r karaf --gid=8181 \
43     && useradd -rm -g karaf --uid=8181 karaf \
44     && chown -R karaf:karaf /opt/opendaylight 
45
46 USER karaf
47
48 EXPOSE 8101 
49 EXPOSE 8181
50
51 CMD ./start_docker.sh