docker run -v mounts data volumes abnormally, and the container status is always restarting

docker run -v mounts data volumes abnormally, and the container status is always restarting

Problems:

After adding the -v parameter to docker run, the container will always be in the restarting state. Removing the -v parameter will allow it to run normally.

Find the problem:

Use docker logs 'containerId'

This containerId is the containerId returned after docker run

As you can see, it is a permission denied issue.

Solving the problem:

Add parameters when running docker: add --privileged=true

For example:

docker run -dit -e MYSQL_ROOT_PASSWORD=123456 --name saasdev-mysql --restart always -v /home/data/mysql:/var/lib/mysql --privileged=true -p 3308:3306 mysql:5.6

The problem was successfully solved and the container started normally

A little explanation:

--privileged=true

With this parameter, the root in the container has real root permissions.

Otherwise, the root in the container has only the permissions of an ordinary user outside.

A container started with privileged can see many devices on the host and can mount them.

It even allows you to start a docker container within a docker container

Supplement: docker --restart=always parameter docker restarts the container automatically

When you add the parameter --restart=always when creating a container, the container will automatically start when Docker is restarted.

Directions:

docker container update --restart=always container name

The operation examples are as follows:

[root@localhost mnt]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46cdfc60b7a6 nginx "nginx -g 'daemon ..." About a minute ago Up 42 seconds 80/tcp n3
79d55a734c26 nginx "nginx -g 'daemon ..." About a minute ago Up 42 seconds 80/tcp n2
f7b2206c019d nginx "nginx -g 'daemon ..." About a minute ago Up 46 seconds 80/tcp n1
[root@localhost mnt]# docker container update --restart=always n1
n1
[root@localhost mnt]# systemctl restart docker 
[root@localhost mnt]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46cdfc60b7a6 nginx "nginx -g 'daemon ..." 2 minutes ago Exited (0) 5 seconds ago n3
79d55a734c26 nginx "nginx -g 'daemon ..." 2 minutes ago Exited (0) 5 seconds ago n2
f7b2206c019d nginx "nginx -g 'daemon ..." 2 minutes ago Up 2 seconds 80/tcp n1
 

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:
  • Docker mounts local directories and data volume container operations
  • A brief summary of Docker container data volume mounting
  • Detailed explanation of container data volumes and data management in Docker
  • Docker data volumes and data containers detailed introduction and examples
  • Docker data volume, data volume container detailed introduction
  • Docker container data volume introduction and operation examples

<<:  A brief discussion of the interesting box model of CSS3 box-sizing property

>>:  MySQL 8.0 New Features - Introduction to Check Constraints

Recommend

Detailed explanation of the difference between CSS link and @import

How to add css in html? There are three ways to s...

Detailed explanation of views in MySQL

view: Views in MySQL have many similarities with ...

Analysis and application of irregular picture waterfall flow principle

The layout problem of irregular picture walls enc...

Detailed explanation of new relational database features in MySQL 8.0

Preface The latest version of MySQL 8.0 is 8.0.4 ...

Detailed explanation of MySQL 5.7.9 shutdown syntax example

mysql-5.7.9 finally provides shutdown syntax: Pre...

Tutorial on configuring and using i3 window manager in Linux

In this article, I will show you how to install a...

JavaScript to achieve the effect of clicking on the self-made menu

This article shares the specific code of JavaScri...

How to change the encoding to utf-8 in mysql version 5.7 under windows

Preface I just started learning MySQL and downloa...

Detailed explanation of Linux host name modification command

Linux change hostname command 1. If you only need...

How to configure Nginx virtual host in CentOS 7.3

Experimental environment A minimally installed Ce...

Introduction to the use of the indeterminate property of the checkbox

When we use the folder properties dialog box in Wi...

Multiple ways to calculate age by birthday in MySQL

I didn't use MySQL very often before, and I w...

Use nginx to dynamically convert image sizes to generate thumbnails

The Nginx ngx_http_image_filter_module module (ng...

Why do select @@session.tx_read_only appear in DB in large quantities?

Find the problem When retrieving the top SQL stat...