简体   繁体   English

在docker中,为什么将数据卷容器安装到容器上会使其停止工作?

[英]In docker, why does mounting a data volume container to a container makes it stop working?

I am using this docker image and was able to successfully run it as a container(using the docker run command present in dockerhub). 我正在使用此Docker映像 ,并能够成功将其作为容器运行(使用dockerhub中存在的docker run命令)。 But I wanted to make the /var/www/ folder of the said container to be persistent. 但我想使上述容器的/ var / www /文件夹保持不变。

So, I tried this command to run the container with a volume mapped to it. 因此,我尝试使用此命令运行带有映射到其上的卷的容器。

docker run -v /home/ejandra/ispconfig:/var/www --name ispconfig -e MAILMAN_EMAIL_HOST=test.com -e MAILMAN_EMAIL=test@test.com -e MAILMAN_PASS=pass -d -p 20:20 -p 21:21 -p 30000:30000 -p 30001:30001 -p 30002:30002 -p 30003:30003
-p 30004:30004 -p 30005:30005 -p 30006:30006 -p 30007:30007 -p 30008:30008 -p 30009:30009 -p 80:80 -p 443:443 -p 8080:8080 -p 53:53 -p 2222:22 jerob/docker-ispconfig /start.sh

This is to map to a data volume whichever the contents of /var/www are. 这将映射到数据卷,无论/var/www的内容是什么。 The volume mapping works because whenever I try to add a new text file to /var/www via shell access, i see the file in /home/ejandra/ispconfig . 卷映射之所以有效,是因为每当我尝试通过外壳访问将新的文本文件添加到/var/www ,我都会在/home/ejandra/ispconfig看到该文件。 However, when I go to https://my-ip:8080 , my browser says, "the site can't be reached". 但是,当我访问https:// my-ip:8080时 ,我的浏览器显示“无法访问该站点”。 What could be the reason that my container suddenly stopped working after adding a data volume? 添加数据卷后容器突然停止工作的原因可能是什么?

I was able to achieve what you wanted by first copying all the stuff to the folder on the host machine and then running the container. 通过首先将所有内容复制到主机上的文件夹,然后运行容器,我能够实现您想要的目标。 So, this is what I did: 所以,这就是我所做的:

First, run the container as you normally do: 首先,像平常一样运行容器:

sudo docker run -name ispconfig -e MAILMAN_EMAIL_HOST=test.com \
     -e MAILMAN_EMAIL=test@test.com -e MAILMAN_PASS=pass -d \
     -p 20:20 -p 21:21 -p 30000:30000 -p 30001:30001 -p 30002:30002 \
     -p 30003:30003 -p 30004:30004 -p 30005:30005 -p 30006:30006 \
     -p 30007:30007 -p 30008:30008 -p 30009:30009 -p 80:80 -p 443:443 \
     -p 8080:8080 -p 53:53 -p 2222:22 jerob/docker-ispconfig /start.sh

Then go inside the container and tar and copy the existing folders to the host machine: 然后进入容器和tar,然后将现有文件夹复制到主机:

$ sudo docker exec -ti ispconfig bash
root@398592d4afe9:/# DEFAULT_ROUTE=$(ip route show default \
                    | awk '/default/ {print $3}')
root@398592d4afe9:/var/www# tar -cvzf /tmp/www.tar.gz /var/www/
tar: Removing leading `/' from member names
/var/www/
/var/www/php-fcgi-scripts/
/var/www/php-fcgi-scripts/ispconfig/
/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter
/var/www/php-fcgi-scripts/apps/
/var/www/php-fcgi-scripts/apps/.php-fcgi-starter
/var/www/ispconfig
/var/www/html/
/var/www/html/index.html
/var/www/apps/
/var/www/webalizer/
root@398592d4afe9:/# scp -rv /tmp/www.tar.gz nwani@${DEFAULT_ROUTE}:
The authenticity of host '172.17.42.1 (172.17.42.1)' can't be established.
ECDSA key fingerprint is 7d:77:b7:54:3a:a5:00:37:94:55:4b:68:8d:2c:89:26.
Are you sure you want to continue connecting (yes/no)? yes
nwani@172.17.42.1's password: 

Then exit out of the container and delete it. 然后退出容器并将其删除。

root@398592d4afe9:/# exit
$ sudo docker rm -f ispconfig

Then extract the copied tar ball: 然后提取复制的tar球:

$ sudo tar -xf /tmp/www.tar.gz -C /home/nwani/
$ sudo ls /home/nwani/var/www/ -l
total 16
drwxr-xr-x 2 5002 5003 4096 Sep  3  2015 apps
drwxr-xr-x 2 root root 4096 Sep  3  2015 html
lrwxrwxrwx 1 root root   34 Sep  3  2015 ispconfig -> /usr/local/ispconfig/interface/web
drwxr-xr-x 4 root root 4096 Sep  3  2015 php-fcgi-scripts
drwxr-xr-x 2 root root 4096 Sep  3  2015 webalizer

Now, run the container again, but this time, mount the data directory: 现在,再次运行容器,但是这次,安装数据目录:

sudo docker run -name ispconfig -v /home/nwani/var/www/:/var/www \
     -e MAILMAN_EMAIL_HOST=test.com -e MAILMAN_EMAIL=test@test.com \
     -e MAILMAN_PASS=pass -d -p 20:20 -p 21:21 -p 30000:30000 \
     -p 30001:30001 -p 30002:30002 -p 30003:30003 -p 30004:30004 \
     -p 30005:30005 -p 30006:30006 -p 30007:30007 -p 30008:30008 \
     -p 30009:30009 -p 80:80 -p 443:443 -p 8080:8080 -p 53:53 \
     -p 2222:22 jerob/docker-ispconfig /start.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM