发生错误时如何将文件复制到Docker容器:没有这样的容器? [英] How can I copy files to a docker container when error happened:Nosuch container?

查看:101
本文介绍了发生错误时如何将文件复制到Docker容器:没有这样的容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对docker还是陌生的,所以,如果我有任何错误的想法,请指出.谢谢〜

I am new about docker, so ,if any wrong thoughts come from me ,please point out it.Thanks~

我的目标是在docker中运行由我或我所属的团队开发的Web服务器.

I aim at running a web server that was developed by me ,or a team I belong to,in the docker.

所以,我考虑了三个步骤:

So, I thought out three steps:

有一个图像,将Web文件复制到其中,然后运行container.so,我执行以下步骤:

Have a image ,copy the web files into it,and run the container.so,I do the step below:

1-获取docker映像.

1- get a docker image.

我尝试这样: docker pull centos ,这样我就可以基于centos获得映像.这里,我并不关心centos的版本,当然,它的版本是6.7或,只是标记为:最新.

I try like this : docker pull centos, so that I can get a image based on centos.Here, I did not care about the version of centos,of course, it's version is 6.7 or ,just taged:latest.

在这里,我通过 docker images 检查该图像,我可以看到这样的图像:

Here,I check the image by docker images,and I can see it like this:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              d123f4e55e12        3 weeks ago         196.6 MB

所以,我认为这一步骤成功了.

So,I think this step successed.

2-尝试将本地系统中的文件复制到容器中.

2- try copying the files in local system to the container.

我停在路径:/tornado上,其中有一个名为fordocker的文件夹.

I stop at the path: /tornado,which had a folder named fordocker .The

fordocker包含Web服务器文件.

fordocker contains the web-server files.

我尝试这样的公共场所(基于指南):

I try commonds like this(based on the guide):

docker cp fordocker/ d123f4e55e12:/web

但是!错误来了:

Error response from daemon: No such container: d123f4e55e12

3-如果我成功复制了文件,我可以这样尝试: docker run -d centos xxx python web.py .

3- if I copy the files successfully,I could try like this:docker run -d centos xxx python web.py.

此步骤会出错?我还不知道.

This step will come error?I don't know yet.

我搜索了很多,但没有解释这种现象.

I searched a lot ,but do not explain the phenomenon.

似乎除了我以外,每个人只要使用公共资源就能成功.

It seemed that everyone,beside me ,use the commond would succes.

那么,问题来了:

1-我认为的方法可行吗?我必须通过个人资料创建图像吗?

1- Is the method I thought out feasible? Must I create a images through profile?

2-如果该方法可行,错误会出在哪里?通用cp是否基于我未做的其他事情?

2- Where comes the error if the method is feasible? Did the commond cp based on otherthings that I had not done?

3-如果该方法不可行怎么办?自己创建图片?

3- What should I do if the method is not feasible?Create a image myself?

祝你有美好的一天〜

推荐答案

您有docker映像和docker容器.那不一样.

You have docker images and docker container. That is different.

您拉动或构建图像.

启动图像时,它成为正在运行的容器.

When you launch an image, it becomes a running container.

映像不是正在运行的容器,因此,您将无法在映像内复制文件.

An image is not a running container, and so, you will not be able to copy a file inside an image.

我不知道这是您想做什么,但是您可以

I do not know if this what you want to do, but you may

1)启动图片

docker run ...

2)复制或修改文件

docker ps

显示正在运行的容器,因此您可以

shows your running container, and so you can

docker cp ...

此正在运行的容器中的文件

a file inside this running container

3)可能使用以下方式保存此修改后的图片

3) maybe save this modified image with

docker commit ...

但是通常,如果要修改映像,则可以修改Dockerfile,这样您就可以使用这样的命令轻松构建新映像

But usually, if you want to modify an image, you modify the Dockerfile, and so you can easily build a new image with such a command

docker build -t myuser/myimage:321.

请注意最后一个点,这意味着您使用本地的Dockerfile.

Notice the final dot, it means you use the Dockerfile that is local.

例如,参见Nginx的Dockerfile

See for example a Dockerfile for Nginx

https://github.com/nginxinc/docker-nginx/blob/c8bfb9b5260d4ad308deac5343b73b027f684375/mainline/stretch/Dockerfile

这篇关于发生错误时如何将文件复制到Docker容器:没有这样的容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆