当前位置:网站首页>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

边栏推荐
- 最新版抽奖盲盒运营版
- C graphical tutorial (Fourth Edition)_ Chapter 15 interface: interfacesamplep268
- The latest version of blind box mall thinkphp+uniapp
- Xctf mobile--app3 problem solving
- Bert running error: attributeerror: module'tensorflow contrib. tpu' has no attribute 'InputPipelineConfig'
- 阿里 & 蚂蚁自研 IDE
- Simple use and precautions of kotlin's array array and set list
- [combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
- Image component in ETS development mode of openharmony application development
- ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
猜你喜欢

Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board

【数据库原理复习题】

【数据挖掘复习题】

GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈

How to convert a decimal number to binary in swift

studio All flavors must now belong to a named flavor dimension. Learn more

(最新版) Wifi分销多开版+安装框架

(latest version) WiFi distribution multi format + installation framework

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

Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
随机推荐
强大的头像制作神器微信小程序
Idea full text search shortcut ctr+shift+f failure problem
Redhat5 installing socket5 proxy server
【习题六】【数据库原理】
Dix règles de travail
Mysqlbetween implementation selects the data range between two values
有限状态机FSM
Using swift language features, write a pseudo-random number generator casually
C graphical tutorial (Fourth Edition)_ Chapter 18 enumerator and iterator: enumerator samplep340
OpenHarmony应用开发之ETS开发方式中的Image组件
Openstack node address change
4. 无线体内纳米网:电磁传播模型和传感器部署要点
低代码平台国际化多语言(i18n)技术方案
Detailed explanation of the most complete constraintlayout in history
[ArcGIS user defined script tool] vector file generates expanded rectangular face elements
GCN thinking - word2vec directly calculates text classification
2022-01-27 use liquibase to manage MySQL execution version
Enable SASL authentication for memcached
【数据挖掘复习题】
【数据库原理复习题】