在Docker与Rancher环境中无法启动WSO2 IS启动脚本的问题
I've run into this exact problem with WSO2 containers before—let's break down what's going wrong and how to fix it.
The Root Cause
When you use wso2server.sh start, the script launches the WSO2 IS process in the background and exits immediately. Since Docker containers rely on the main process to stay running, once that startup script finishes, Docker thinks the container's work is done and stops it. That's why you're seeing the "Expected state running but got stopped" error.
Solution 1: Run WSO2 IS in Foreground Mode
WSO2's startup script supports running the server in the foreground, which keeps the main process active (and your container running). You just need to drop the start parameter:
Option A: Update your Dockerfile
Change the CMD to run the script without the start flag (or use the run parameter, depending on your WSO2 IS version):
CMD ["/opt/wso2is/bin/wso2server.sh"]
Or explicitly use run if needed:
CMD ["/opt/wso2is/bin/wso2server.sh", "run"]
Option B: Update your docker-compose.yml
Modify the command section to use the foreground mode:
command: ["/opt/wso2is/bin/wso2server.sh"]
Or:
command: - /opt/wso2is/bin/wso2server.sh - run
Solution 2: Check Your Volume Mount
You're mounting a host directory to /opt/wso2is in the container. If that host directory is empty or missing critical WSO2 IS files, the startup script might fail silently (or exit early). Here's how to debug this:
- Temporarily remove the
volumessection from your docker-compose.yml and start the container. If it stays running, the issue is with your host volume. - If you need to keep the volume, copy the working WSO2 IS files from a running container to your host directory first:
docker cp 676d5bc5cf18:/opt/wso2is /home/dockserver/stacks/inclouding/volume/wso2is
This ensures your host volume has all the necessary files for the server to start.
Solution 3: Use Exec-Form CMD/Command
Always prefer the exec form (array syntax) for CMD and command in Docker. This ensures signals like SIGTERM are properly passed to the WSO2 process, making shutdown cleaner and preventing unexpected exits. Avoid shell-form commands like CMD /opt/wso2is/bin/wso2server.sh start—they spawn a shell as the main process, which can cause issues with signal handling and process lifecycle.
Final Check
After making these changes, redeploy your stack in Rancher. The container should stay running, and you'll be able to access WSO2 IS on ports 9443/9763 as expected.
内容的提问来源于stack exchange,提问作者jordi

