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

How to configure MySQL on Ubuntu 16.04 server and enable remote connection

background I am learning nodejs recently, and I r...

MySQL paging analysis principle and efficiency improvement

MySQL paging analysis principle and efficiency im...

VMware Workstation virtual machine installation operation method

Virtual machines are very convenient testing soft...

Vue+flask realizes video synthesis function (drag and drop upload)

Table of contents We have written about drag and ...

How to implement one-click deployment of nfs in linux

Server Information Management server: m01 172.16....

How to separate static and dynamic state by combining Apache with Tomcat

Experimental environment Apache and Tomcat are bo...

Analyzing the troublesome Aborted warning in MySQL through case studies

This article mainly introduces the relevant conte...

Summary of CSS3 practical methods (recommended)

1. Rounded border: CSS CodeCopy content to clipbo...

Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

Table of contents 1. Back up the old MySQL5.7 dat...

How to run a project with docker

1. Enter the directory where your project war is ...

Detailed explanation of data type issues in JS array index detection

When I was writing a WeChat applet project, there...

CSS solution for centering elements with variable width and height

1. Horizontal center Public code: html: <div c...

jQuery achieves fade-in and fade-out effects

Before using jQuery to complete the fade-in and f...

Example of how to implement value transfer between WeChat mini program pages

Passing values ​​between mini program pages Good ...