我有一个 dockerized 项目。我构建,将文件从主机系统复制到 docker 容器中,然后 shell 到容器中,发现该文件不存在。docker cp应该如何工作?
$ docker build -q -t foo .
Sending build context to Docker daemon 64 kB
Step 0 : FROM ubuntu:14.04
---> 2d24f826cb16
Step 1 : MAINTAINER Brandon Istenes <redacted@email.com>
---> Using cache
---> f53a163ef8ce
Step 2 : RUN apt-get update
---> Using cache
---> 32b06b4131d4
Successfully built 32b06b4131d4
$ docker cp ~/.ssh/known_hosts foo:/root/.ssh/known_hosts
$ docker run -it foo bash
WARNING: Your kernel does not support memory swappiness capabilities, memory swappiness discarded.
root@421fc2866b14:/# ls /root/.ssh
root@421fc2866b14:/#
Run Code Online (Sandbox Code Playgroud)
因此,图像和容器的名称有些混淆。显然,cp 操作作用于与我用 run 命令提出的容器不同的容器上。无论如何,正确的程序是:
# Build the image, call it foo-build
docker build -q -t foo-build .
# Create a container from the image called foo-tmp
docker create --name foo-tmp foo-build
# Run the copy command on the container
docker cp /src/path foo-tmp:/dest/path
# Commit the container as a new image
docker commit foo-tmp foo
# The new image will have the files
docker run foo ls /dest
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11883 次 |
| 最近记录: |