Installez Docker sur CentOS. Voir la page officielle pour plus de détails https://docs.docker.com/engine/installation/linux/docker-ce/centos/
yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce
systemctl enable docker
systemctl start docker
(1). Créer une image de CentOS7
docker pull centos:centos7
docker run -it centos:centos7 /bin/bash
(2). Introduisez les polices LibreOffice et IPA
yum update -y
yum install libreoffice* ipa-*-fonts
(3). Créer un dossier de travail
mkdir /tmp/
exit
(4). Vérifiez le CONTAINER ID de Docker
docker ps -a
(5). Commit avec le nom "office" Entrez le CONTAINER ID confirmé précédemment dans * $ {CONTAINER ID} *.
docker commit ${CONTAINER ID} office
(6). Vérifiez si cela fonctionne correctement On suppose que le fichier "/var/tmp/test.xlsx" existe sur CentOS. S'il est exécuté normalement, "/var/tmp/test.pdf" sera généré.
docker run --rm=true -it -v /var/tmp:/tmp office libreoffice --headless --nologo --nofirststartwizard --convert-to pdf --outdir /tmp /tmp/test.xlsx
Ceci est un exemple pour démarrer le docker avec la classe de processus Java.
	/**
	 *Convertir en PDF via Docker
	 * @param excelFileName
	 * @param pdfFileName
	 * @return
	 * @throws InterruptedException
	 */
    public boolean convertPDF(String excelFileName) throws InterruptedException {
		//Spécification de la commande de démarrage
		String[] command = {
				"docker", "run", "--rm=true", "-v", "/var/tmp:/tmp", "office", "libreoffice", "--headless"
                , "--nologo", "--nofirststartwizard", "--convert-to", "pdf", "--outdir"
                ,"/tmp", "/tmp/"+excelFileName };
        ProcessBuilder pb = new ProcessBuilder(command);
		try {
            //Exécution de la commande
			Process process = pb.start();
            //Attendez le résultat de l'exécution de la commande
			int ret = process.waitFor();
            //Sortie standard
			InputStream is = process.getInputStream();	
			printInputStream(is);
            //Erreur standard
			InputStream es = process.getErrorStream();	
			printInputStream(es);
		}
		catch (Exception e) {
			return false;
		}
		return true;
    }
    
	/**
	 *Affichage de la sortie standard / d'erreur
	 * @param is
	 * @throws IOException
	 */
    public static void printInputStream(InputStream is) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		try {
			for (;;) {
				String line = br.readLine();
				if (line == null) break;
				System.out.println(line);
			}
		} finally {
			br.close();
		}
	}
        Recommended Posts