GNU/make and docker, terminate the running process
up vote
0
down vote
favorite
I'm using GNU/make (linux) to wrap some docker command, I don't use docker everyday so I'll forget the usage soon, one of those wrapper is make serve
, it run docker run
with php -S
(built-in server) as command, it start and listen for connections.
To stop it I should use ^C , I believe (but I'm not sure) the problem to be make
intercepting the signal, the make's target fail but the php process (and the docker instance) remain running, I've to manually stop it.
I tried passing --sig-proxy=true
and false
but with no effect, but I'm running the instance with a pseudo terminal (-t
) so this was expected.
I wrote a bash wrapper to echo some message when some signal is trapped (EXIT TERM SIGTERM SIGQUIT KILL SIGKILL
) and exec php -S
, but I don't see any message.
I'm not sure what happen when ^C is pressed on a running make, if the signal (and what) is propagated only to the forked sh -c
, and why that wouldn't work with docker run
.
I'd like to know if someone else had this problem and solved or if someone can think of some alternative solution.
edit
Makefile
:
all:
.PHONY: docker-build serve
docker-build:
docker build -f Dockerfile -t sigtest:v1 .
serve:
docker run -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
test with make docker-build
and then make serve
2nd edit
I managed to wrap docker run
with a shell script (I'm not sure about trap syntax in posix shells, eventually I'll take a look)
make
seems to be sending INT
the first time and and then EXIT
#!/bin/sh
pid=$$
trap 'trap - INT EXIT; echo " signal received, wait..."; docker stop -t 0 sig${pid}; exit' INT EXIT
docker run --name=sig${pid} "$@"
and then in the Makefile
serve:
-./docker-run.sh -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
I was hoping to not have to name the instances but that's the simplest way I can think of.
docker signals gnu-make
add a comment |
up vote
0
down vote
favorite
I'm using GNU/make (linux) to wrap some docker command, I don't use docker everyday so I'll forget the usage soon, one of those wrapper is make serve
, it run docker run
with php -S
(built-in server) as command, it start and listen for connections.
To stop it I should use ^C , I believe (but I'm not sure) the problem to be make
intercepting the signal, the make's target fail but the php process (and the docker instance) remain running, I've to manually stop it.
I tried passing --sig-proxy=true
and false
but with no effect, but I'm running the instance with a pseudo terminal (-t
) so this was expected.
I wrote a bash wrapper to echo some message when some signal is trapped (EXIT TERM SIGTERM SIGQUIT KILL SIGKILL
) and exec php -S
, but I don't see any message.
I'm not sure what happen when ^C is pressed on a running make, if the signal (and what) is propagated only to the forked sh -c
, and why that wouldn't work with docker run
.
I'd like to know if someone else had this problem and solved or if someone can think of some alternative solution.
edit
Makefile
:
all:
.PHONY: docker-build serve
docker-build:
docker build -f Dockerfile -t sigtest:v1 .
serve:
docker run -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
test with make docker-build
and then make serve
2nd edit
I managed to wrap docker run
with a shell script (I'm not sure about trap syntax in posix shells, eventually I'll take a look)
make
seems to be sending INT
the first time and and then EXIT
#!/bin/sh
pid=$$
trap 'trap - INT EXIT; echo " signal received, wait..."; docker stop -t 0 sig${pid}; exit' INT EXIT
docker run --name=sig${pid} "$@"
and then in the Makefile
serve:
-./docker-run.sh -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
I was hoping to not have to name the instances but that's the simplest way I can think of.
docker signals gnu-make
Could you post a simplified version of yourMakefile
which reproduces the issue?
– Danila Kiver
Nov 21 at 16:16
Hello @DanilaKiver, see the edit, thanks
– Alex
Nov 21 at 17:11
Had kind of similar issue before and switched to docker-compose. It has commands for managing the whole lifecycle including starting and stopping services.
– Alex
Nov 21 at 17:47
Alex, sure, perhaps almost any solution removing make remove the issue, but that's the point, I been using make for years now, I'd like to continue. But you gave me an idea, maybe wrapping docker run with a script outside of the docker instead of wrapping php inside... I'll give a try, thank you
– Alex
Nov 21 at 18:40
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using GNU/make (linux) to wrap some docker command, I don't use docker everyday so I'll forget the usage soon, one of those wrapper is make serve
, it run docker run
with php -S
(built-in server) as command, it start and listen for connections.
To stop it I should use ^C , I believe (but I'm not sure) the problem to be make
intercepting the signal, the make's target fail but the php process (and the docker instance) remain running, I've to manually stop it.
I tried passing --sig-proxy=true
and false
but with no effect, but I'm running the instance with a pseudo terminal (-t
) so this was expected.
I wrote a bash wrapper to echo some message when some signal is trapped (EXIT TERM SIGTERM SIGQUIT KILL SIGKILL
) and exec php -S
, but I don't see any message.
I'm not sure what happen when ^C is pressed on a running make, if the signal (and what) is propagated only to the forked sh -c
, and why that wouldn't work with docker run
.
I'd like to know if someone else had this problem and solved or if someone can think of some alternative solution.
edit
Makefile
:
all:
.PHONY: docker-build serve
docker-build:
docker build -f Dockerfile -t sigtest:v1 .
serve:
docker run -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
test with make docker-build
and then make serve
2nd edit
I managed to wrap docker run
with a shell script (I'm not sure about trap syntax in posix shells, eventually I'll take a look)
make
seems to be sending INT
the first time and and then EXIT
#!/bin/sh
pid=$$
trap 'trap - INT EXIT; echo " signal received, wait..."; docker stop -t 0 sig${pid}; exit' INT EXIT
docker run --name=sig${pid} "$@"
and then in the Makefile
serve:
-./docker-run.sh -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
I was hoping to not have to name the instances but that's the simplest way I can think of.
docker signals gnu-make
I'm using GNU/make (linux) to wrap some docker command, I don't use docker everyday so I'll forget the usage soon, one of those wrapper is make serve
, it run docker run
with php -S
(built-in server) as command, it start and listen for connections.
To stop it I should use ^C , I believe (but I'm not sure) the problem to be make
intercepting the signal, the make's target fail but the php process (and the docker instance) remain running, I've to manually stop it.
I tried passing --sig-proxy=true
and false
but with no effect, but I'm running the instance with a pseudo terminal (-t
) so this was expected.
I wrote a bash wrapper to echo some message when some signal is trapped (EXIT TERM SIGTERM SIGQUIT KILL SIGKILL
) and exec php -S
, but I don't see any message.
I'm not sure what happen when ^C is pressed on a running make, if the signal (and what) is propagated only to the forked sh -c
, and why that wouldn't work with docker run
.
I'd like to know if someone else had this problem and solved or if someone can think of some alternative solution.
edit
Makefile
:
all:
.PHONY: docker-build serve
docker-build:
docker build -f Dockerfile -t sigtest:v1 .
serve:
docker run -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
test with make docker-build
and then make serve
2nd edit
I managed to wrap docker run
with a shell script (I'm not sure about trap syntax in posix shells, eventually I'll take a look)
make
seems to be sending INT
the first time and and then EXIT
#!/bin/sh
pid=$$
trap 'trap - INT EXIT; echo " signal received, wait..."; docker stop -t 0 sig${pid}; exit' INT EXIT
docker run --name=sig${pid} "$@"
and then in the Makefile
serve:
-./docker-run.sh -t --rm sigtest:v1 gosu ubuntu:ubuntu php7.0 -S 0.0.0.0:8081 -t /home/ubuntu
I was hoping to not have to name the instances but that's the simplest way I can think of.
docker signals gnu-make
docker signals gnu-make
edited Nov 22 at 7:04
asked Nov 21 at 15:15
Alex
2,50511427
2,50511427
Could you post a simplified version of yourMakefile
which reproduces the issue?
– Danila Kiver
Nov 21 at 16:16
Hello @DanilaKiver, see the edit, thanks
– Alex
Nov 21 at 17:11
Had kind of similar issue before and switched to docker-compose. It has commands for managing the whole lifecycle including starting and stopping services.
– Alex
Nov 21 at 17:47
Alex, sure, perhaps almost any solution removing make remove the issue, but that's the point, I been using make for years now, I'd like to continue. But you gave me an idea, maybe wrapping docker run with a script outside of the docker instead of wrapping php inside... I'll give a try, thank you
– Alex
Nov 21 at 18:40
add a comment |
Could you post a simplified version of yourMakefile
which reproduces the issue?
– Danila Kiver
Nov 21 at 16:16
Hello @DanilaKiver, see the edit, thanks
– Alex
Nov 21 at 17:11
Had kind of similar issue before and switched to docker-compose. It has commands for managing the whole lifecycle including starting and stopping services.
– Alex
Nov 21 at 17:47
Alex, sure, perhaps almost any solution removing make remove the issue, but that's the point, I been using make for years now, I'd like to continue. But you gave me an idea, maybe wrapping docker run with a script outside of the docker instead of wrapping php inside... I'll give a try, thank you
– Alex
Nov 21 at 18:40
Could you post a simplified version of your
Makefile
which reproduces the issue?– Danila Kiver
Nov 21 at 16:16
Could you post a simplified version of your
Makefile
which reproduces the issue?– Danila Kiver
Nov 21 at 16:16
Hello @DanilaKiver, see the edit, thanks
– Alex
Nov 21 at 17:11
Hello @DanilaKiver, see the edit, thanks
– Alex
Nov 21 at 17:11
Had kind of similar issue before and switched to docker-compose. It has commands for managing the whole lifecycle including starting and stopping services.
– Alex
Nov 21 at 17:47
Had kind of similar issue before and switched to docker-compose. It has commands for managing the whole lifecycle including starting and stopping services.
– Alex
Nov 21 at 17:47
Alex, sure, perhaps almost any solution removing make remove the issue, but that's the point, I been using make for years now, I'd like to continue. But you gave me an idea, maybe wrapping docker run with a script outside of the docker instead of wrapping php inside... I'll give a try, thank you
– Alex
Nov 21 at 18:40
Alex, sure, perhaps almost any solution removing make remove the issue, but that's the point, I been using make for years now, I'd like to continue. But you gave me an idea, maybe wrapping docker run with a script outside of the docker instead of wrapping php inside... I'll give a try, thank you
– Alex
Nov 21 at 18:40
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The problem is not in using make
but in the Signal handling. Here is an article describing it.
As I said before docker-compose
manages the whole lifecycle of your services.
Here is a basic example of your app using docker-compose
. By make up
and make down
(including ^C
), so you can start and stop your service.
Makefile
:
all:
.PHONY: docker-build serve
build:
docker-compose build
up:
docker-compose up
down:
docker-compose down
docker-compose.yml
:
version: '3.3'
services:
my_service:
build: .
ports:
- "8080:8080"
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
RUN mkdir -p /home/ubuntu
RUN php7.0 --version
ENTRYPOINT php7.0 -S 0.0.0.0:8080
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
docker-compose build
just builds service anddocker-compose up
will startphp
server by executingENTRYPOINT php7.0 -S 0.0.0.0:8080
line fromDockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted
– Alex
Nov 21 at 19:24
thanks for the effort
– Alex
Nov 21 at 20:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The problem is not in using make
but in the Signal handling. Here is an article describing it.
As I said before docker-compose
manages the whole lifecycle of your services.
Here is a basic example of your app using docker-compose
. By make up
and make down
(including ^C
), so you can start and stop your service.
Makefile
:
all:
.PHONY: docker-build serve
build:
docker-compose build
up:
docker-compose up
down:
docker-compose down
docker-compose.yml
:
version: '3.3'
services:
my_service:
build: .
ports:
- "8080:8080"
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
RUN mkdir -p /home/ubuntu
RUN php7.0 --version
ENTRYPOINT php7.0 -S 0.0.0.0:8080
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
docker-compose build
just builds service anddocker-compose up
will startphp
server by executingENTRYPOINT php7.0 -S 0.0.0.0:8080
line fromDockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted
– Alex
Nov 21 at 19:24
thanks for the effort
– Alex
Nov 21 at 20:02
add a comment |
up vote
1
down vote
The problem is not in using make
but in the Signal handling. Here is an article describing it.
As I said before docker-compose
manages the whole lifecycle of your services.
Here is a basic example of your app using docker-compose
. By make up
and make down
(including ^C
), so you can start and stop your service.
Makefile
:
all:
.PHONY: docker-build serve
build:
docker-compose build
up:
docker-compose up
down:
docker-compose down
docker-compose.yml
:
version: '3.3'
services:
my_service:
build: .
ports:
- "8080:8080"
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
RUN mkdir -p /home/ubuntu
RUN php7.0 --version
ENTRYPOINT php7.0 -S 0.0.0.0:8080
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
docker-compose build
just builds service anddocker-compose up
will startphp
server by executingENTRYPOINT php7.0 -S 0.0.0.0:8080
line fromDockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted
– Alex
Nov 21 at 19:24
thanks for the effort
– Alex
Nov 21 at 20:02
add a comment |
up vote
1
down vote
up vote
1
down vote
The problem is not in using make
but in the Signal handling. Here is an article describing it.
As I said before docker-compose
manages the whole lifecycle of your services.
Here is a basic example of your app using docker-compose
. By make up
and make down
(including ^C
), so you can start and stop your service.
Makefile
:
all:
.PHONY: docker-build serve
build:
docker-compose build
up:
docker-compose up
down:
docker-compose down
docker-compose.yml
:
version: '3.3'
services:
my_service:
build: .
ports:
- "8080:8080"
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
RUN mkdir -p /home/ubuntu
RUN php7.0 --version
ENTRYPOINT php7.0 -S 0.0.0.0:8080
The problem is not in using make
but in the Signal handling. Here is an article describing it.
As I said before docker-compose
manages the whole lifecycle of your services.
Here is a basic example of your app using docker-compose
. By make up
and make down
(including ^C
), so you can start and stop your service.
Makefile
:
all:
.PHONY: docker-build serve
build:
docker-compose build
up:
docker-compose up
down:
docker-compose down
docker-compose.yml
:
version: '3.3'
services:
my_service:
build: .
ports:
- "8080:8080"
Dockerfile
:
FROM ubuntu:16.04
RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends php7.0-cli gosu
RUN useradd -ms /bin/bash ubuntu
RUN mkdir -p /home/ubuntu
RUN php7.0 --version
ENTRYPOINT php7.0 -S 0.0.0.0:8080
edited Nov 21 at 19:18
answered Nov 21 at 19:07
Alex
1,0121710
1,0121710
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
docker-compose build
just builds service anddocker-compose up
will startphp
server by executingENTRYPOINT php7.0 -S 0.0.0.0:8080
line fromDockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted
– Alex
Nov 21 at 19:24
thanks for the effort
– Alex
Nov 21 at 20:02
add a comment |
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
docker-compose build
just builds service anddocker-compose up
will startphp
server by executingENTRYPOINT php7.0 -S 0.0.0.0:8080
line fromDockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted
– Alex
Nov 21 at 19:24
thanks for the effort
– Alex
Nov 21 at 20:02
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
That would be nice but I've some other target in the makefile, for instance to build from some source and exit (without listening), with different configurations (dev and prod at least), can docker-compose handle the scenario?
– Alex
Nov 21 at 19:18
docker-compose build
just builds service and docker-compose up
will start php
server by executing ENTRYPOINT php7.0 -S 0.0.0.0:8080
line from Dockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted– Alex
Nov 21 at 19:24
docker-compose build
just builds service and docker-compose up
will start php
server by executing ENTRYPOINT php7.0 -S 0.0.0.0:8080
line from Dockerfile
. There are more complicated examples available docs.docker.com/compose/gettingstarted– Alex
Nov 21 at 19:24
thanks for the effort
– Alex
Nov 21 at 20:02
thanks for the effort
– Alex
Nov 21 at 20:02
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415116%2fgnu-make-and-docker-terminate-the-running-process%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you post a simplified version of your
Makefile
which reproduces the issue?– Danila Kiver
Nov 21 at 16:16
Hello @DanilaKiver, see the edit, thanks
– Alex
Nov 21 at 17:11
Had kind of similar issue before and switched to docker-compose. It has commands for managing the whole lifecycle including starting and stopping services.
– Alex
Nov 21 at 17:47
Alex, sure, perhaps almost any solution removing make remove the issue, but that's the point, I been using make for years now, I'd like to continue. But you gave me an idea, maybe wrapping docker run with a script outside of the docker instead of wrapping php inside... I'll give a try, thank you
– Alex
Nov 21 at 18:40