当前位置:网站首页>Solve system has not been booted with SYSTEMd as init system (PID 1) Can‘t operate.
Solve system has not been booted with SYSTEMd as init system (PID 1) Can‘t operate.
2022-07-03 13:02:00 【duapple】
docker Container usage systemctl
With ubuntu As a reference .
Pull the container
Direct pull
Use
docker pull ubuntuDirect pull .adopt Dockerfile Pull
Dockerfile:
# base image FROM ubuntu:18.04 # build Parameters ARG user=duapple # Metadata LABEL maintainer="hejiang" email="[email protected]" # Installation dependency #RUN apt-get update && apt-get install -y sudo # Add users : give sudo jurisdiction , Specified password RUN useradd --create-home --no-log-init --shell /bin/bash ${user} \ && adduser ${user} sudo \ && echo "${user}:123123" | chpasswd # Change the user's UID and GID #RUN usermod -u 1000 ${user} && usermod -G 1000 ${user} # Specify the working directory of the container WORKDIR /home/${user} # Specifies the login user for the container USER {user}Pull :
$ docker build -t ubuntu1804:test .

If you don't have the ability to surf the Internet , You may not install it yet sudo, After entering the system , Set up the software source before installing sudo.
# Configure container
Here we use docker Take the image pulled as an example . Directly pull the image , You need to manually create non root user , The rest of the operation is the same as the following .
nothing Dockerfile The situation of , New user script , Before execution, you need to Install first sudo.add_user.sh:
#!/bin/bash
user=$1
echo "add user: ${user}"
useradd -d /home/${user} -m ${user}
passwd ${user}
usermod -g ${user} -G root ${user}
chmod u+w /etc/sudoers
echo "${user} ALL=(ALL:ALL) ALL" >> /etc/sudoers
chmod u-w /etc/sudoers
usermod -s /bin/bash ${user}
# add_user.sh duapple
Be careful : Need to use systemctl, You can't use non root The user starts the container , Otherwise, just set /sbin/init Start as the first process ,systemctl Still can't use
Create the container and run it . Be careful : Need to set up --privileged Parameters , Make sure you can get the real root jurisdiction .
$ docker run --privileged -itd --name ubuntu_test -u root ubuntu1804:test /bin/bash
$ docker exec -it ubuntu_test /bin/bash

modify root Password and install sudo.
# passwd
# apt update
# apt install sudo
Switch to duapple user . test sudo, And install systemd.
# exit
$ docker exec -it -u duapple ubuntu_test /bin/bash
$ sudo apt install systemd
$ ls -al /sbin/init

download ssh, To test .
$ sudo apt install ssh
$ sudo systemctl start ssh
Error will be reported at this time :

The first process to configure the container :
$ exit
$ docker stop ubuntu_test
$ sudo systemctl stop docker
# sudo su
#
modify config.v2.json Medium Path and Cmd , from /bin/bash Set to /sbin/init . Be careful : Be sure to close it first docker service , Modify the configuration to take effect .
# vim /var/lib/docker/containers/0f22b0c68de9819eb72d02094a5d23d3ee66e4eabd3563b9190f48ac83c55f22/config.v2.json

Save the changes , restart docker, Restart again docker Containers , Reconfigure it .
$ docker start ubuntu_test
$ docker exec -it -u duapple ubuntu_test /bin/bash
$ sudo systemctl start ssh
$ sudo systemctl status ssh

边栏推荐
- Sword finger offer14 the easiest way to cut rope
- 关于CPU缓冲行的理解
- Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
- An example of newtonjason
- Analysis of the influence of voltage loop on PFC system performance
- [comprehensive question] [Database Principle]
- [data mining review questions]
- 2022-02-10 introduction to the design of incluxdb storage engine TSM
- The latest version of lottery blind box operation version
- [network counting] Chapter 3 data link layer (2) flow control and reliable transmission, stop waiting protocol, backward n frame protocol (GBN), selective retransmission protocol (SR)
猜你喜欢
![[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number](/img/9d/6118b699c0d90810638f9b08d4f80a.jpg)
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number

IDEA 全文搜索快捷键Ctr+Shift+F失效问题

最新版抽奖盲盒运营版

Integer case study of packaging

解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.

社交社区论坛APP超高颜值UI界面

Deeply understand the mvcc mechanism of MySQL

自抗扰控制器七-二阶 LADRC-PLL 结构设计

【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】

【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
随机推荐
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
I'm too lazy to write more than one character
GCN thinking - word2vec directly calculates text classification
SSH登录服务器发送提醒
2022-01-27 research on the minimum number of redis partitions
对业务的一些思考
关于CPU缓冲行的理解
[judgment question] [short answer question] [Database Principle]
剑指 Offer 11. 旋转数组的最小数字
Powerful avatar making artifact wechat applet
Mysqlbetween implementation selects the data range between two values
IDEA 全文搜索快捷键Ctr+Shift+F失效问题
阿里 & 蚂蚁自研 IDE
2022-01-27 redis cluster brain crack problem analysis
An example of newtonjason
The latest version of blind box mall thinkphp+uniapp
Enable SASL authentication for memcached
(latest version) WiFi distribution multi format + installation framework
Xctf mobile--app2 problem solving