Detailed explanation of the solution to the error of using systemctl to start the service in docker

Detailed explanation of the solution to the error of using systemctl to start the service in docker

Docker version:

[root@localhost gae_proxy]# docker version
Client:
 Version: 1.10.3
 API version: 1.22
 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64
 Go version: go1.6.3
 Git commit: d381c64-unsupported
 Built: Thu Aug 4 13:21:17 2016
 OS/Arch: linux/amd64

Server:
 Version: 1.10.3
 API version: 1.22
 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64
 Go version: go1.6.3
 Git commit: d381c64-unsupported
 Built: Thu Aug 4 13:21:17 2016
 OS/Arch: linux/amd64

Image version

[root@b2ca5610d3da /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 

When starting the service through systemctl in docker, an error message such as Failed to get D-Bus connection: Operation not permitted is always reported.

[root@25d27693a24d ~]# systemctl start sshd
Failed to get D-Bus connection: Operation not permitted

The solution is to run /usr/sbin/init when docker run. for example:

[root@localhost /]# docker run -tid --name hadoopbase centos/hadoopbase:v001 /usr/sbin/init

The container that is running in this way can use systemctl to start the service. Some people say that the problem of error when running through systemctl has been solved in CentOS7.2, but I still encounter such a problem in actual operation.

Another solution is to execute the /usr/sbin/init command through CMD when generating the image file through Dockerfile, that is: CMD ["/usr/sbin/init"];

Reference: https://github.com/docker/docker/issues/7459
https://github.com/docker/docker/issues/2296

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Setting up Docker proxy under CentOS 7 (environment variable configuration of Systemd service under Linux)
  • Use of docker system command set

<<:  Detailed explanation of Mysql's method of optimizing order by statement

>>:  How to run JavaScript in Jupyter Notebook

Recommend

Comparison of CSS shadow effects: drop-Shadow and box-Shadow

Drop-shadow and box-shadow are both CSS propertie...

Detailed explanation of Vite's new experience

What is Vite? (It’s a new toy on the front end) V...

Tutorial on upgrading from Centos7 to Centos8 (with pictures and text)

If you upgrade in a formal environment, please ba...

MySQL high availability cluster deployment and failover implementation

Table of contents 1. MHA 1. Concept 2. Compositio...

The textarea tag cannot be resized and cannot be dragged with the mouse

The textarea tag size is immutable Copy code The c...

Implementing a simple timer based on Vue method

Vue's simple timer is for your reference. The...

7 ways to vertically center elements with CSS

【1】Know the width and height of the centered elem...

A brief discussion on CSS blocking merging and other effects

Non-orthogonal margins When margin is used, it wi...

How to redirect URL using nginx rewrite

I often need to change nginx configuration at wor...

Steps to enable MySQL database monitoring binlog

Preface We often need to do something based on so...

Example code of layim integrating right-click menu in JavaScript

Table of contents 1. Effect Demonstration 2. Impl...

JavaScript to switch multiple pictures

This article shares the specific code of JavaScri...