Docker - V cannot start the container as soon as it is mapped. How to check it? How to solve it?

Alibaba cloud Q & A 2022-02-13 06:13:10 阅读数:667

docker start container soon mapped.

The native environment window10

Docker Engine


Dockerfile The documents are as follows


The process is as follows

create mirror

docker image build -t hello-php-demo:0.0.1 .

Run the image directly without mounting 【 normal 】

docker run -it --rm -p 80:80 hello-php-demo:0.0.1 /bin/bash

take docker Of /var/www/html Mount to the current directory

docker run -it --rm -p 80:80 hello-php-demo:0.0.1 -v "$PWD/":/var/www/html /bin/bash

I just added more -v "$PWD/":/var/www/html After running, it is found that a section of , It's not a mistake , The container is not running


I've searched for a long time. The question is to add –privileged=true Parameters , The actual test doesn't work

Check the reason why the container failed to start ( I can't see the reason ....)

Server version: Apache/2.4.48 (Debian)Server built: 2021-08-12T11:51:47

doubt 1: How to mount to succeed

doubt 2: In fact, if you run this container like this, the inside apache It also needs to be started manually , How to make it run automatically CMD

["/usr/sbin/apache2ctl","-D","FOREGROUND"] I can't run this after I use it ........

Take the answer 1:

The first question is :

Use -v Parameter mounting is OK , The problem with your screenshot is because -v Wrong position .

docker run -it --rm -p 80:80 hello-php-demo:0.0.1 -v "$PWD/":/var/www/html /bin/bash

It should be carried out in this way :

docker run -it --rm -p 80:80 -v "$PWD/":/var/www/html hello-php-demo:0.0.1 /bin/bash

docker run Put the parameter in front of the image name , You put it in the back is equivalent to putting -v Parameters to apache2ctl 了 . You can try to execute... In a container apache2ctl -v , Can reproduce that " error " Output. .

The second question is : hold /bin/bash Get rid of , Run it like this :

docker run -d -p 80:80 -v "$PWD/":/var/www/html hello-php-demo:0.0.1

copyright:author[Alibaba cloud Q & A],Please bring the original link to reprint, thank you.