0

If I have a Docker file that has at the end:

ENTRYPOINT /bin/bash

and run the container via docker run and type in the terminal

gulp

that gives me running gulp that I can easily terminate with Ctrl+C

but when I put gulp as default command to Dockerfile this way:

CMD ["/bin/bash", "-c", "gulp"]

or this:

ENTRYPOINT ["/bin/bash", "-c", "gulp"]

then when I run container via docker run the gulp is running but I can't terminate it via Ctrl+C hotkey.

The Dockerfile I used to build the image:

FROM node:8

RUN apt-get update \
    && apt-get upgrade -y \
    && apt-get install -y libltdl-dev

WORKDIR /home/workspace

RUN npm install gulp -g

#works but cant kill gulp with Ctrl+C
#CMD ["/bin/bash", "-c", "gulp"]

#works but cant kill gulp with Ctrl+C
#ENTRYPOINT ["/bin/bash", "-c", "gulp"]

# need to type command gulp in cli to run it
# but I'm able to terminate gulp with Ctrl+C
ENTRYPOINT /bin/bash

It makes sense to me I can't terminate the default command for the container that is defined in Dockerfile because there would be no other command that could run once I terminate the default.

How can I state in Dockerfile that I want to run /bin/bash as default and on top of that gulp so If I terminate gulp I'll be switched back to the bash command line prompt?

Jimmix
  • 5,644
  • 6
  • 44
  • 71

2 Answers2

0

Since gulp is a build tool, you'd generally run it in the course of building your container, not while you're starting it. Your Dockerfile might look roughly like

FROM node:8
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install
COPY . ./
RUN gulp
CMD yarn run start

When you run docker build, along the way it will print out things like

---> b35f4035db3f
Step 6/7 : RUN gulp
---> Running in 02071fceb21b

The important thing is that the last hex string that gets printed out in each step (the line before each Dockerfile command) is a valid Docker image ID. If your build goes wrong, you can

host$ sudo docker run --rm -it b35f4035db3f bash
root@38ed4261ab0f:/app# gulp

Once you've finished debugging the issue, you can check whatever fixes into your source control system, and rebuild the image as needed later.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • I use the container with gulp to run other containers, at the moment of building its image I don't want to define any dependencies, pointing out what it should do etc. I want to have non tailored/general gulp container that I can run and point a dir where a gulpfile.js exists to perform tasks that are defined there. Since copying `package.json yarn.lock ./` does not suit the need. Secondly I don't even have these files but just `dockerfile.js` everything works ok but i need to do 1.`docker run ...`, 2.`gulp` and to terminate gulp 3.`Ctrl+C`. How to combine 1+2 without issue Ctrl+C? – Jimmix Nov 05 '18 at 15:11
0

Gulp is build tool you need to install using run command. This will commit the changes on top of your base image.
If you want to use it as a default command either using ENTRYPOINT or CMD in your dockerfile, then you can definitely not kill it with a ctrl+c since it is not a shell process, but in fact a container that you are running.
If in case you have your dockerfile an ENTRYPOINT. You can stop the container using docker stop.

NOTE: A container cannot be killed using ctrl+c, it needs to be stopped via:
docker stop container_name

Vinod Kumar
  • 562
  • 5
  • 12
  • ok, then is there any way to define in Dockerfile that i want to run `/bin/bash` and as a second command gulp `as if` I was typing it into terminal? because if I do the following sequence 1 I have Dockerfile with Entrypoint or CMD set to `/bin/bash` I run container `docker run -it ...` and once I logged into terminal I type `gulp` I'm able to terminate it witth `Ctrl+C` but when I put `ENTRYPOINT ["/bin/bash", "-c", "gulp"]` in Dockerfile I can't terminate gulp with `Ctrl+C` so how to make equivalent of first scenario and put it into Dockerfile? – Jimmix Nov 05 '18 at 15:18
  • Make a script containing both the commands and add the script in CMD exec mode – Vinod Kumar Nov 05 '18 at 17:04