Learn how to specify the port that your PHP application uses.
IBM Cloud Code Engine is a fully managed, serverless platform that runs your containerized workloads, including web apps, microservices, event-driven functions or batch jobs. The Code Engine experience is designed so that you can focus on writing code and not on the infrastructure that is needed to host it.
When you choose PHP Apache as a base image, your docker container will expose port 80 by default. This is the official PHP image on Dockerhub.
Specifying a different port (such as 8080) using an
EXPOSE statement in your Dockerfile does not work. In this blog post, I will share how to specify the port that your PHP application uses.
- IBM Cloud account and access to deploy apps in IBM Cloud Code Engine
- Basic understanding of how to write a Dockerfile
- Deploying a code using
Current problem and symptom
Your Dockerfile probably looks like the following, in the simplest form:
Once you kick off build and deploy, you will see a new image successfully built and saved on your image repository, but deployment will fail due to timeout and the log will not show adequate information:
Essentially, this problem is caused by the port mismatch. You would have defined whatever port you defined in the Dockerfile as a listening port on the Code Engine side. However, your PHP application is still using the default port 80, so Code Engine cannot find your application.
How to specify the port in your Dockerfile
In PHP Apache, the /etc/apache2/ports.conf configuration file stores the directives that determine the TCP ports Apache is listening on. The listen directive in the configuration file determines the port Apache will bind to and prioritise. So, let's overwrite it to 8080:
Once you build and deploy again, it should work:
Alternatively, you can make Code Engine to use the default port 80. Edit your revision setting and modify listening port:
Having a trouble deploying an app?
Please feel free to contact IBM client support for any questions or concerns.