Reputation: 466
I'm new to docker, trying to build my the first docker container on AWS free tier account t2.micro instance
I am able to build my docker based on below Dockerfile.
FROM java:8
COPY content-service /
RUN chmod +x /bin/start.sh
CMD bash -C '/bin/start.sh'
EXPOSE 8081
MAINTAINER Velu
It's failing and exits while is trying to run the container command following error message is getting.
[ec2-user@ip-172-31-30-38 cis-docker]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
content-service latest 9fa3ca5a8ac3 10 minutes ago 705.7 MB
docker.io/java 8 d23bdf5b1b1b 8 months ago 643.1 MB
[ec2-user@ip-172-31-30-38 cis-docker]$ sudo docker --debug run -p 8082:8082 content-service
DEBU[0000] framesize: 18
Starting service.
DEBU[0000] Corrupted prefix: []
DEBU[0000] [hijack] End of stdout
Any help would be appreciated.
Upvotes: 3
Views: 8967
Reputation: 466
I found and fixed this issue.
In my start.sh script last line I have this below line.
java -cp $CLASS_PATH $JVM_OPTIONS $CLASS_NAME ${ARGUMENTS[@]} & echo $! > $PID_FILE
In that line, I did remove this & echo $! > $PID_FILE,
Working:
java -cp $CLASS_PATH $JVM_OPTIONS $CLASS_NAME ${ARGUMENTS[@]}
Upvotes: 1
Reputation: 994
I ran your docker file by copying a simple shell script which prints "hello" on to console. It ran successfully.
Also, it does not seem like your docker container is exiting. Docker is running your shell script and exiting gracefully. To verify, check the exit code of your docker run command by running the below command as soon as your docker run is finished.
echo $?
If the above command prints "0" on to the screen then docker did not fail.
If you are expecting your shell script to run as a background daemon you need to make sure that your script does not exit. The reason why docker container is exiting as soon as your shell scriptspecified in CMD line your Dockerfile is finished executing is because Docker's design philosophy is to run one process per container. In your case that single process is your shell script. So start whatever service you are starting in your shell script as a foreground process and the container will keep running as long as that service is running. As soon as that service dies your container dies which is what you might want.
Hope that helps.
Upvotes: 1