Docker solution for logging in without root privileges

Docker solution for logging in without root privileges

When you use the docker command for the first time, you will be prompted for permission issues.

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.37/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied

Solution:

1. Use sudo to obtain root privileges;

Second, add the current user to the docker user group;

sudo groupadd docker #Add docker user group sudo gpasswd -a $USER docker #Add the logged in user to the docker user group newgrp docker #Update user group docker ps #Test whether the docker command can be used normally with sudo

Supplement: Problem and solution of root user being unable to log in when deploying mysql with docker

Today, when using the mysql:5.7 docker image, I found that I could not log in using the root user after starting the container. Here are the steps:

1. Pull the mysql5.7 image

$ docker pull mysql:5.7

2. Create a bridge

$docker network create -d bridge blog_network

3. Run the mysql container

 docker container run -it --rm --name mysql --network blog_network -v $PWD/data/myscript/:/docker-entrypoint-initdb.d/ --env MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

4. Enter the container

$ docker exec -it mysql bash
#mysql -u root -p

The password 123456 set in step 3 returns the result:

Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

5. The solution is as follows

Step 2: Run the container command and modify it as follows:

 $ docker container run -it --detach --name mysql --network blog_network -p 3306:3306 -v $PWD/data/myscript/:/docker-entrypoint-initdb.d/ --env MYSQL_RANDOM_ROOT_PASSWORD=yes mysql:5.7
$ docker container logs mysql| grep 'GENERATED ROOT PASSWORD: ' | awk -F': ' '{print $2}'

A string will be returned, which is the actual password of our root user: log in with this password and then change the root user password.

ooli0OhMoo1Ieg1CeiYieSohleeVi1oh
$mysql -u root -p

After entering mysql using the above password, you need to change the password.

mysql>update mysql.user set authentication_string=password('newpassword') where user='root';
mysql>flush privileges;
mysql>exit

As shown in the figure:

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
  • How to modify the root password of mysql in docker
  • How to change the root password in a container using 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

<<:  Various transformation effects of HTML web page switching

>>:  Media query combined with rem layout in CSS3 to adapt to mobile screens

Recommend

Introduction to several ways to introduce CSS in HTML

Table of contents 1. Embed CSS styles directly in...

Detailed explanation of MySQL 8's new feature ROLE

What problems does MySQL ROLE solve? If you are a...

How to get the maximum or minimum value of a row in sql

Original data and target data Implement SQL state...

Summary of Operator Operations That Are Very Error-Prone in JavaScript

Table of contents Arithmetic operators Abnormal s...

...

A line of CSS code that crashes Chrome

General CSS code will only cause minor issues wit...

How to prompt and open hyperlink a

<br />The countless information on the Inter...

Detailed explanation of how Vue components transfer values ​​to each other

Table of contents Overview 1. Parent component pa...

How to construct a table index in MySQL

Table of contents Supports multiple types of filt...

Summary of the execution issues between mysql max and where

Execution problem between mysql max and where Exe...

Implementation of Docker CPU Limit

1. --cpu=<value> 1) Specify how much availa...

Use and optimization of MySQL COUNT function

Table of contents What does the COUNT function do...

HTML form tag tutorial (5): text field tag

<br />This tag is used to create a multi-lin...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

Detailed explanation of the use of HTML header tags

HTML consists of two parts: head and body ** The ...