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

Implementation of select multiple data loading optimization in Element

Table of contents Scenario Code Implementation Su...

Mysql master-slave synchronization configuration scheme under Centos7 system

Preface Recently, when working on a high-availabi...

Detailed steps to change the default password when installing MySQL in Ubuntu

Step 1: Enter the directory: cd /etc/mysql, view ...

The difference between JS pre-parsing and variable promotion in web interview

Table of contents What is pre-analysis? The diffe...

Summary of the top ten problems of MySQL index failure

Table of contents background 1. The query conditi...

JavaScript to implement voice queuing system

Table of contents introduce Key Features Effect d...

Copy the contents of one file to the end of another file in linux

Problem description: For example, the content of ...

Analysis of MySQL multi-table joint query operation examples

This article describes the MySQL multi-table join...

How to start a transaction in MySQL

Preface This article mainly introduces how to sta...

How to perform query caching in MySQL and how to solve failures

We all know that we need to understand the proper...

Implement group by based on MySQL to get the latest data of each group

Preface: The group by function retrieves the firs...

How to understand Vue's simple state management store mode

Table of contents Overview 1. Define store.js 2. ...

Implementation of vertical centering with unknown height in CSS

This article mainly introduces the implementation...

MySQL 5.7.20 Green Edition Installation Detailed Graphic Tutorial

First, let’s understand what MySQL is? MySQL is a...