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

Causes and solutions for MySQL master-slave synchronization delay

For historical reasons, MySQL replication is base...

Sample code for making desktop applications with vue + Electron

1.vue packaging Here we use the vue native packag...

Use of MySQL DATE_FORMAT function

Suppose Taobao encourages people to shop during D...

Install and build a server environment of PHP+Apache+MySQL on CentOS

Yum (full name Yellow dog Updater, Modified) is a...

Solution to forgetting the administrator password of mysql database

1. Enter the command mysqld --skip-grant-tables (...

Solution to 2059 error when connecting Navicat to MySQL

Recently, when I was learning Django, I needed to...

5 Commands to Use the Calculator in Linux Command Line

Hello everyone, I am Liang Xu. When using Linux, ...

Simple tips to increase web page loading speed

The loading speed of a web page is an important in...

Detailed explanation of the frame and rules attributes of the table in HTML

The frame and rules attributes of the table tag c...

Problems and solutions of using jsx syntax in React-vscode

Problem Description After installing the plugin E...

Basic usage of @Font-face and how to make it compatible with all browsers

@Font-face basic introduction: @font-face is a CSS...

Use of Linux crontab command

1. Command Introduction The contab (cron table) c...

Detailed explanation of TypeScript 2.0 marked union types

Table of contents Constructing payment methods us...

mysql 5.7.18 winx64 password change

After MySQL 5.7.18 is successfully installed, sin...