John Davidson

Circle CI Docker Image: Php + Java

0 comments
Message:


I found separate Circle CI docker image for Php and Java.


- image: circleci/php:7.2.30
- image: circleci/openjdk:11.0.3-jdk-stretch

And I have run command to use 'java' command and it fails because it runs before jdk library.
Is there any circleci docker image with Php + Java?


or how to wait the 'run' command until docker image is ready?



My Answer:
You can create a custom Circle CI Docker image that includes both PHP and Java by combining the existing PHP and Java images. Here's an example Dockerfile that you can use to create a custom image:

Dockerfile
FROM circleci/php:7.2.30

RUN sudo apt-get update && sudo apt-get install -y openjdk-11-jdk

CMD ["/bin/bash"]


Save this Dockerfile in a directory and build the image using the following command:


docker build -t circleci/php-java .


Then, you can use this custom image in your Circle CI configuration file:

yaml
version: 2.1
jobs:
build:
docker:
- image: circleci/php-java

steps:
- run:
name: Check PHP version
command: php -v

- run:
name: Check Java version
command: java -version


This configuration will ensure that both PHP and Java are available in the same Docker image and you can run commands for both languages in your Circle CI job.

Alternatively, if you want to wait for the Java environment to be ready before running a command, you can use a script to check for the availability of Java before executing the command. Here's an example:

yaml
version: 2.1
jobs:
build:
docker:
- image: circleci/php:7.2.30

steps:
- run:
name: Wait for Java
command: |
while ! java -version; do
sleep 1
done

- run:
name: Run Java command
command: java -version


In this configuration, the job will wait for the Java environment to be ready before running the Java command. You can adjust the sleep interval as needed to ensure that Java is fully available before proceeding with the command.

Rate this post

3 of 5 based on 1079 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us