How to enable systemd on Dockerfile with Ubuntu18.04
up vote
0
down vote
favorite
I know Systemd is not recommended on Docker containers but is it possible?
I have staging/prod environments on Ubuntu 18.04 cloud VMs deployed with Ansible;
My current dev environment is a Ubuntu 18.04 Vagrantfile
that uses the same Ansible playbook.yml
of staging/prod
Now I'm trying to replace the Vagrantfile
with a Dockerfile
for development but the Ansible playbook.yml
fails when applying systemd modules. I would like to have systemd
on my dev environment as well so that I can test changes on my playbook.yml
local. Any idea how I can do it?
If I try to build with Dockerfile
and playbook.yml
as below, I get an error Failed to find required executable systemctl in paths
.
If I add RUN apt-get install systemd
to Dockerfile
nd try to build, I get an error System has not been booted with systemd as init system
Sample Dockerfile
:
FROM ubuntu:18.04
ADD . /app
WORKDIR /app
# Install Python3 pip used to install Ansible
RUN apt-get update && apt-get install -y
python3-pip
# Install Ansible
RUN pip3 install --trusted-host pypi.python.org ansible
RUN ansible-playbook playbook.yml -i inventory
EXPOSE 80
Sample playbook.yml
:
---
- name: Ansible playbook to setup dev environment
hosts: all
vars:
ansible_python_interpreter: "/usr/bin/python3"
debug: True
become: yes
become_method: sudo
tasks:
- name: Copy App Gunicorn systemd config
template:
src: app_gunicorn.service
dest: /etc/systemd/system/
- name: Enable App Gunicorn on systemd
systemd: state=started name=app_gunicorn
Sample inventory
:
docker-dev ansible_host=localhost ansible_connection=local
docker ubuntu systemd
add a comment |
up vote
0
down vote
favorite
I know Systemd is not recommended on Docker containers but is it possible?
I have staging/prod environments on Ubuntu 18.04 cloud VMs deployed with Ansible;
My current dev environment is a Ubuntu 18.04 Vagrantfile
that uses the same Ansible playbook.yml
of staging/prod
Now I'm trying to replace the Vagrantfile
with a Dockerfile
for development but the Ansible playbook.yml
fails when applying systemd modules. I would like to have systemd
on my dev environment as well so that I can test changes on my playbook.yml
local. Any idea how I can do it?
If I try to build with Dockerfile
and playbook.yml
as below, I get an error Failed to find required executable systemctl in paths
.
If I add RUN apt-get install systemd
to Dockerfile
nd try to build, I get an error System has not been booted with systemd as init system
Sample Dockerfile
:
FROM ubuntu:18.04
ADD . /app
WORKDIR /app
# Install Python3 pip used to install Ansible
RUN apt-get update && apt-get install -y
python3-pip
# Install Ansible
RUN pip3 install --trusted-host pypi.python.org ansible
RUN ansible-playbook playbook.yml -i inventory
EXPOSE 80
Sample playbook.yml
:
---
- name: Ansible playbook to setup dev environment
hosts: all
vars:
ansible_python_interpreter: "/usr/bin/python3"
debug: True
become: yes
become_method: sudo
tasks:
- name: Copy App Gunicorn systemd config
template:
src: app_gunicorn.service
dest: /etc/systemd/system/
- name: Enable App Gunicorn on systemd
systemd: state=started name=app_gunicorn
Sample inventory
:
docker-dev ansible_host=localhost ansible_connection=local
docker ubuntu systemd
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I know Systemd is not recommended on Docker containers but is it possible?
I have staging/prod environments on Ubuntu 18.04 cloud VMs deployed with Ansible;
My current dev environment is a Ubuntu 18.04 Vagrantfile
that uses the same Ansible playbook.yml
of staging/prod
Now I'm trying to replace the Vagrantfile
with a Dockerfile
for development but the Ansible playbook.yml
fails when applying systemd modules. I would like to have systemd
on my dev environment as well so that I can test changes on my playbook.yml
local. Any idea how I can do it?
If I try to build with Dockerfile
and playbook.yml
as below, I get an error Failed to find required executable systemctl in paths
.
If I add RUN apt-get install systemd
to Dockerfile
nd try to build, I get an error System has not been booted with systemd as init system
Sample Dockerfile
:
FROM ubuntu:18.04
ADD . /app
WORKDIR /app
# Install Python3 pip used to install Ansible
RUN apt-get update && apt-get install -y
python3-pip
# Install Ansible
RUN pip3 install --trusted-host pypi.python.org ansible
RUN ansible-playbook playbook.yml -i inventory
EXPOSE 80
Sample playbook.yml
:
---
- name: Ansible playbook to setup dev environment
hosts: all
vars:
ansible_python_interpreter: "/usr/bin/python3"
debug: True
become: yes
become_method: sudo
tasks:
- name: Copy App Gunicorn systemd config
template:
src: app_gunicorn.service
dest: /etc/systemd/system/
- name: Enable App Gunicorn on systemd
systemd: state=started name=app_gunicorn
Sample inventory
:
docker-dev ansible_host=localhost ansible_connection=local
docker ubuntu systemd
I know Systemd is not recommended on Docker containers but is it possible?
I have staging/prod environments on Ubuntu 18.04 cloud VMs deployed with Ansible;
My current dev environment is a Ubuntu 18.04 Vagrantfile
that uses the same Ansible playbook.yml
of staging/prod
Now I'm trying to replace the Vagrantfile
with a Dockerfile
for development but the Ansible playbook.yml
fails when applying systemd modules. I would like to have systemd
on my dev environment as well so that I can test changes on my playbook.yml
local. Any idea how I can do it?
If I try to build with Dockerfile
and playbook.yml
as below, I get an error Failed to find required executable systemctl in paths
.
If I add RUN apt-get install systemd
to Dockerfile
nd try to build, I get an error System has not been booted with systemd as init system
Sample Dockerfile
:
FROM ubuntu:18.04
ADD . /app
WORKDIR /app
# Install Python3 pip used to install Ansible
RUN apt-get update && apt-get install -y
python3-pip
# Install Ansible
RUN pip3 install --trusted-host pypi.python.org ansible
RUN ansible-playbook playbook.yml -i inventory
EXPOSE 80
Sample playbook.yml
:
---
- name: Ansible playbook to setup dev environment
hosts: all
vars:
ansible_python_interpreter: "/usr/bin/python3"
debug: True
become: yes
become_method: sudo
tasks:
- name: Copy App Gunicorn systemd config
template:
src: app_gunicorn.service
dest: /etc/systemd/system/
- name: Enable App Gunicorn on systemd
systemd: state=started name=app_gunicorn
Sample inventory
:
docker-dev ansible_host=localhost ansible_connection=local
docker ubuntu systemd
docker ubuntu systemd
asked Nov 19 at 22:15
vmenezes
238214
238214
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
That's a perfect example where the docker-systemctl-replacement script should be used.
It has been developed to allow ansible scripts to target both virtual machines and docker containers. You do not need to enable a real systemd, just overwrite /usr/bin/systemctl in operating systems that are otherwise under systemd control. The docker container will then look good enough for ansible, whereas I am more used to use the general 'service:' module instead of the specific 'systemd:' module.
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
The suggesteddocker-systemctl-replacement
worked perfectly! All I had to do was to downloadsystemctl3.py
from that repo and add it to my Dockerfile asCOPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
andRUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
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
accepted
That's a perfect example where the docker-systemctl-replacement script should be used.
It has been developed to allow ansible scripts to target both virtual machines and docker containers. You do not need to enable a real systemd, just overwrite /usr/bin/systemctl in operating systems that are otherwise under systemd control. The docker container will then look good enough for ansible, whereas I am more used to use the general 'service:' module instead of the specific 'systemd:' module.
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
The suggesteddocker-systemctl-replacement
worked perfectly! All I had to do was to downloadsystemctl3.py
from that repo and add it to my Dockerfile asCOPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
andRUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
add a comment |
up vote
1
down vote
accepted
That's a perfect example where the docker-systemctl-replacement script should be used.
It has been developed to allow ansible scripts to target both virtual machines and docker containers. You do not need to enable a real systemd, just overwrite /usr/bin/systemctl in operating systems that are otherwise under systemd control. The docker container will then look good enough for ansible, whereas I am more used to use the general 'service:' module instead of the specific 'systemd:' module.
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
The suggesteddocker-systemctl-replacement
worked perfectly! All I had to do was to downloadsystemctl3.py
from that repo and add it to my Dockerfile asCOPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
andRUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
That's a perfect example where the docker-systemctl-replacement script should be used.
It has been developed to allow ansible scripts to target both virtual machines and docker containers. You do not need to enable a real systemd, just overwrite /usr/bin/systemctl in operating systems that are otherwise under systemd control. The docker container will then look good enough for ansible, whereas I am more used to use the general 'service:' module instead of the specific 'systemd:' module.
That's a perfect example where the docker-systemctl-replacement script should be used.
It has been developed to allow ansible scripts to target both virtual machines and docker containers. You do not need to enable a real systemd, just overwrite /usr/bin/systemctl in operating systems that are otherwise under systemd control. The docker container will then look good enough for ansible, whereas I am more used to use the general 'service:' module instead of the specific 'systemd:' module.
answered Nov 20 at 12:08
Guido U. Draheim
1,169119
1,169119
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
The suggesteddocker-systemctl-replacement
worked perfectly! All I had to do was to downloadsystemctl3.py
from that repo and add it to my Dockerfile asCOPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
andRUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
add a comment |
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
The suggesteddocker-systemctl-replacement
worked perfectly! All I had to do was to downloadsystemctl3.py
from that repo and add it to my Dockerfile asCOPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
andRUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
That's why the docker-systemctl-replacement script can be also installed as the docker-entrypoint script - it will then start all enabled services in the container. Upon "docker stop" it will also "systemctl stop" all those services correctly before exiting the container itself. (Effectively, systemctl.py is both a service manager and an init-daemon).
– Guido U. Draheim
Nov 20 at 12:17
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
Ah, I hadn't realized from a brief glance that it would actually parse systemd units and emulate the various settings in order to provide the appropriate environment. Neat!
– larsks
Nov 20 at 12:19
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
By the way, some working examples can be found at github.com/gdraheim/docker-systemctl-images
– Guido U. Draheim
Nov 20 at 12:21
The suggested
docker-systemctl-replacement
worked perfectly! All I had to do was to download systemctl3.py
from that repo and add it to my Dockerfile as COPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
and RUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
The suggested
docker-systemctl-replacement
worked perfectly! All I had to do was to download systemctl3.py
from that repo and add it to my Dockerfile as COPY deploy/environments/dev-docker/files/systemctl3.py /usr/bin/systemctl
and RUN test -L /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
– vmenezes
Nov 20 at 19:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53383431%2fhow-to-enable-systemd-on-dockerfile-with-ubuntu18-04%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