From 7f86c057f9d0078716897b9aad0158aa1b0b49b5 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 15 Apr 2020 01:09:23 +0300 Subject: [PATCH] Another start script to run multiple processes in the same docker container --- Dockerfile | 6 +++--- start/start.sh | 8 ++++---- start/start2.sh | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 start/start2.sh diff --git a/Dockerfile b/Dockerfile index 89d98d1..5ccea30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,8 +24,8 @@ COPY --from=builder /app/start/api.sh ./application/api/ RUN chmod +x application/api/api.sh RUN printf '\n\n- Copy application starting script\n' -COPY --from=builder /app/start/start.sh ./application/ -RUN chmod +x application/start.sh +COPY --from=builder /app/start/start2.sh ./application/ +RUN chmod +x application/start2.sh #install static server || Alternativ se poate utiliza si http-server RUN npm install -g serve @@ -38,7 +38,7 @@ WORKDIR /application EXPOSE 80 3001 -CMD ["./start.sh"] +CMD ["./start2.sh"] #CMD ["sh", "-c", "node application/api/createMockDb.js && node application/api/apiServer.js && serve -s application/front -p 80"] #CMD ["serve", "-s", "build", "-p", "80"] diff --git a/start/start.sh b/start/start.sh index 98918ff..7fce83c 100644 --- a/start/start.sh +++ b/start/start.sh @@ -1,18 +1,18 @@ #!/bin/bash # Start the first process and put it in the background -./front/front.sh -D & +./api/api.sh -D & status=$? if [ $status -ne 0 ]; then - echo "Failed to start front: $status" + echo "Failed to start api: $status" exit $status fi # Start the second process -./api/api.sh -D +./front/front.sh -D status=$? if [ $status -ne 0 ]; then - echo "Failed to start api: $status" + echo "Failed to start front: $status" exit $status fi diff --git a/start/start2.sh b/start/start2.sh new file mode 100644 index 0000000..c1c23d5 --- /dev/null +++ b/start/start2.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# turn on bash's job control +set -m + +# Start the primary process and put it in the background +./front/front.sh & + + +# Start the helper process +./api/api.sh + +# the my_helper_process might need to know how to wait on the +# primary process to start before it does its work and returns + +# now we bring the primary process back into the foreground +# and leave it there +fg %1 \ No newline at end of file