当前位置:网站首页>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 ubuntu
Direct 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
边栏推荐
- SSH登录服务器发送提醒
- Everything comes to him who waits
- Powerful avatar making artifact wechat applet
- A large select drop-down box, village in Chaoyang District
- Express abstract classes and methods
- 2022-02-10 introduction to the design of incluxdb storage engine TSM
- 最新版抽奖盲盒运营版
- Kotlin - 改良装饰者模式
- 剑指 Offer 14- I. 剪绳子
- Swift5.7 extend some to generic parameters
猜你喜欢
最新版盲盒商城thinkphp+uniapp
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
initial、inherit、unset、revert和all的区别
Analysis of a music player Login Protocol
Node.js: express + MySQL的使用
4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment
我的创作纪念日:五周年
高效能人士的七个习惯
强大的头像制作神器微信小程序
Xctf mobile--app1 problem solving
随机推荐
How to convert a decimal number to binary in swift
【习题五】【数据库原理】
Method overloading and rewriting
Sword finger offer 16 Integer power of numeric value
A large select drop-down box, village in Chaoyang District
Xctf mobile--app1 problem solving
Grid connection - Analysis of low voltage ride through and island coexistence
【数据库原理复习题】
2022-01-27 redis cluster technology research
C graphical tutorial (Fourth Edition)_ Chapter 18 enumerator and iterator: enumerator samplep340
C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: delegatesamplep245
Sword finger offer 12 Path in matrix
SLF4J 日志门面
我的创作纪念日:五周年
剑指 Offer 16. 数值的整数次方
剑指 Offer 17. 打印从1到最大的n位数
GCN thinking - word2vec directly calculates text classification
Dix règles de travail
Dojo tutorials:getting started with deferrals source code and example execution summary
Swift return type is a function of function