How to change the root password in a container using Docker

How to change the root password in a container using Docker

1. Use the following command to set the ssh password when making dockerfile

RUN echo "root:root" | chpasswd

2. Now you need to change the root password in the container after the container is generated

The docker exec -it centos7.5 root:newpassword | chpasswd command was executed successfully, but the password update failed.

The correct way is as follows:

PASS='newpassword ' && echo -e "KaTeX parse error: Expected 'EOF', got '\n' at position 5: PASS\̲n̲PASS" | docker exec -i centos7.5

Supplement: What is the password after docker pull centos? 【Xiaobaitiankeng】

For the record, the first time I used Baota's docker to pull centos8, when I started the centos8 container, I was prompted to enter a password. I was confused at the time. What was the password? After an hour of work, I finally figured out how to do it. I just ssh to my server and then run

docker exec -it your container name/bin/bash

This will take you directly into the new container. So where is the name of your container? See the picture below

So, I directly execute

docker exec -it funny_tesla /bin/bash

You can enter the centos8 container and do whatever you want. . End~

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • How to obtain a permanent free SSL certificate from Let''s Encrypt in Docker
  • Docker solution for logging in without root privileges
  • How to modify the root password of mysql in docker
  • How to obtain root permissions in a docker container
  • docker cp copy files and enter the container
  • Docker uses root to enter the container
  • Solution to the Docker container not having permission to write to the host directory
  • How to add a certificate to docker

<<:  Summary of some common methods of JavaScript array

>>:  The difference between html Frame, Iframe and Frameset

Recommend

Centos8 builds nfs based on kdc encryption

Table of contents Configuration nfs server (nfs.s...

docker-maven-plugin packages the image and uploads it to a private warehouse

Table of contents 1. Introduction to docker-maven...

Comprehensive understanding of html.css overflow

Comprehensive understanding of html.css overflow ...

Use vertical-align to align input and img

Putting input and img on the same line, the img ta...

Example of how to enable Slow query in MySQL

Preface Slow query log is a very important functi...

How to retrieve password for mysql 8.0.22 on Mac

Mac latest version of MySQL 8.0.22 password recov...

Should I use Bootstrap or jQuery Mobile for mobile web wap

Solving the problem Bootstrap is a CSS framework ...

Docker uses Supervisor to manage process operations

A Docker container starts a single process when i...

Vue+Echart bar chart realizes epidemic data statistics

Table of contents 1. First install echarts in the...

What is flex and a detailed tutorial on flex layout syntax

Flex Layout Flex is the abbreviation of Flexible ...

CentOS server security configuration strategy

Recently, the server has been frequently cracked ...

Management of xinetd-based services installed with RPM packages in Linux

Table of contents Preface 1. Startup management b...

About using Alibaba's iconfont vector icon in Vue

There are many import methods on the Internet, an...