Programing

저장소를 사용하지 않고 한 호스트에서 다른 호스트로 Docker 이미지를 복사하는 방법

lottogame 2020. 9. 27. 12:38
반응형

저장소를 사용하지 않고 한 호스트에서 다른 호스트로 Docker 이미지를 복사하는 방법


비공개 또는 공개 여부에 관계없이 저장소를 사용하지 않고 한 시스템에서 다른 시스템으로 Docker 이미지를 전송하려면 어떻게해야합니까?

저는 VirtualBox에서 자신의 이미지를 재생하고 생성하는 데 익숙하며, 완료되면 실제 사용을 위해 다른 컴퓨터에 배포하려고합니다.

자체 기반 이미지 (예 : Red Hat Linux)를 기반으로하기 때문에 Dockerfile에서 다시 만들 수 없습니다.

사용할 수있는 간단한 명령이 있습니까? 아니면 다른 해결책?

저장 / 내보내기가 비슷한 목적을 달성 할 수있는 것 같습니다 . Docker에서 저장과 내보내기의 차이점무엇입니까?를 참조하십시오 . , 나는 save내 경우에 명령을 선호합니다 .


Docker 이미지를 tar 파일로 저장해야합니다.

docker save -o <path for generated tar file> <image name>

그런 다음 cp, scp또는 rsync(큰 파일에 선호 됨) 과 같은 일반 파일 전송 도구를 사용하여 이미지를 새 시스템에 복사합니다 . 그 후에 이미지를 Docker에로드해야합니다.

docker load -i <path to image tar file>

PS : sudo모든 명령 이 필요할 수 있습니다 .

편집 : -o를 사용하여 파일 이름 (디렉토리뿐 아니라)을 추가해야합니다. 예를 들면 다음과 같습니다.

docker save -o c:/myfile.tar centos:16

SSH를 통해 Docker 이미지 전송, 즉석에서 콘텐츠 압축 :

docker save <image> | bzip2 | \
     ssh user@host 'bunzip2 | docker load'

pv전송이 어떻게 진행되는지 확인하기 위해 파이프 중간에 두는 것도 좋은 생각 입니다.

docker save <image> | bzip2 | pv | \
     ssh user@host 'bunzip2 | docker load'

(자세한 정보 pv: 홈페이지 , 맨 페이지 ).


이미지를 파일 경로 또는 공유 NFS 위치에 저장하려면 다음 예를 참조하십시오.

다음을 수행하여 이미지 ID를 가져옵니다.

sudo docker images

ID가 "matrix-data"인 이미지가 있다고 가정 해 보겠습니다.

ID로 이미지 저장 :

sudo docker save -o /home/matrix/matrix-data.tar matrix-data

경로에서 호스트로 이미지를 복사합니다. 이제 다음을 사용하여 로컬 Docker 설치로 가져옵니다.

sudo docker load -i <path to copied image file>

먼저 Docker 이미지를 zip 파일에 저장합니다.

docker save <docker image name> | gzip > <docker image name>.tar.gz

그런 다음 아래 명령을 사용하여 내 보낸 이미지를 Docker에로드합니다.

zcat <docker image name>.tar.gz | docker load

운영

docker images

호스트의 이미지 목록을 확인합니다. awesomesauce 라는 이미지가 있다고 가정 해 보겠습니다 . 터미널 cd에서 이미지를 내보낼 디렉토리로 이동합니다. 이제 실행 :

docker save awesomesauce:latest > awesomesauce.tar

tar 파일을 썸 드라이브 등에 복사 한 다음 새 호스트 컴퓨터에 복사합니다.

이제 새 호스트에서 다음을 수행하십시오.

docker load < awesomesauce.tar

이제 커피를 마시고 Hacker News를 읽으십시오 ...


컨테이너의 파일 시스템을 평평하게 내보내려면 다음을 사용하십시오.

docker export CONTAINER_ID > my_container.tar

해당 cat my_container.tar | docker import -이미지를 가져 오는 데 사용 합니다.


고정 표시기 기계를 사용하는 경우, 당신은 기계 사이에 이미지를 복사 할 수 있습니다 mach1mach2와를 :

docker $(docker-machine config <mach1>) save <image> | docker $(docker-machine config <mach2>) load

물론 pv진행률 표시기를 얻기 위해 중간에 위치 할 수도 있습니다 .

docker $(docker-machine config <mach1>) save <image> | pv | docker $(docker-machine config <mach2>) load

docker-machine config현재 기본 docker-host를 사용하기 위해 하위 셸 중 하나를 생략 할 수도 있습니다 .

docker save <image> | docker $(docker-machine config <mach>) load

현재 docker-host에서 이미지를 복사하려면 mach

또는

docker $(docker-machine config <mach>) save <image> | docker load

mach현재 도커 호스트 로 복사 합니다.


couchdb-cartridge이미지 ID가 7ebc8510bc2c 인 저장해야한다고 가정합니다 .

stratos@Dev-PC:~$ docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
couchdb-cartridge                      latest              7ebc8510bc2c        17 hours ago        1.102 GB
192.168.57.30:5042/couchdb-cartridge   latest              7ebc8510bc2c        17 hours ago        1.102 GB
ubuntu                                 14.04               53bf7a53e890        3 days ago          221.3 MB

archiveName 이미지를 tar 파일에 저장합니다. 를 사용 /media/sf_docker_vm/하여 이미지를 저장합니다.

stratos@Dev-PC:~$ docker save imageID > /media/sf_docker_vm/archiveName.tar

환경에서 작동하는 방법 (예 FTP: SCP, 등)을 사용하여 archiveName.tar 파일을 새 Docker 인스턴스에 복사합니다 .

docker load새 Docker 인스턴스 에서 명령을 실행하고 이미지 tar 파일의 위치를 ​​지정하십시오.

stratos@Dev-PC:~$ docker load < /media/sf_docker_vm/archiveName.tar

마지막으로 docker images명령을 실행하여 이미지를 사용할 수 있는지 확인합니다.

stratos@Dev-PC:~$ docker images
REPOSITORY                             TAG        IMAGE ID         CREATED             VIRTUAL SIZE
couchdb-cartridge                      latest     7ebc8510bc2c     17 hours ago        1.102 GB
192.168.57.30:5042/couchdb-cartridge   latest     bc8510bc2c       17 hours ago        1.102 GB
ubuntu                                 14.04      4d2eab1c0b9a     3 days ago          221.3 MB

Please find this detailed post.


To transfer images from your local Docker installation to a minikube VM:

docker save <image> | (eval $(minikube docker-env) && docker load)

All other answers are very helpful. I just went through the same problem and figure out an easy way with docker machine scp.

Since Docker Machine v0.3.0, scp was introduced to copy files from one Docker machine to another. This is very convenient if you want copying a file from your local computer to a remote Docker machine such as AWS EC2 or Digital Ocean because Docker Machine is taking care of SSH credentials for you.

  1. Save you images using docker save like:

    docker save -o docker-images.tar app-web
    
  2. Copy images using docker-machine scp

    docker-machine scp ./docker-images.tar remote-machine:/home/ubuntu
    

Assume your remote Docker machine is remote-machine and the directory you want the tar file to be is /home/ubuntu.

  1. Load the Docker image

    docker-machine ssh remote-machine sudo docker load -i docker-images.tar
    

docker-push-ssh is a command line utility I created just for this scenario.

It sets up a temporary private Docker registry on the server, establishes an SSH tunnel from your localhost, pushes your image, then cleans up after itself.

The benefit of this approach over docker save (at the time of writing most answers are using this method) is that only the new layers are pushed to the server, resulting in a MUCH quicker upload.

Oftentimes using an intermediate registry like dockerhub is undesirable, and cumbersome.

https://github.com/brthor/docker-push-ssh

Install:

pip install docker-push-ssh

Example:

docker-push-ssh -i ~/my_ssh_key username@myserver.com my-docker-image

The biggest caveat is that you have to manually add your localhost to Docker's insecure_registries configuration. Run the tool once and it will give you an informative error:

Error Pushing Image: Ensure localhost:5000 is added to your insecure registries.
More Details (OS X): https://stackoverflow.com/questions/32808215/where-to-set-the-insecure-registry-flag-on-mac-os

Where should I set the '--insecure-registry' flag on Mac OS?


You may use sshfs:

$ sshfs user@ip:/<remote-path> <local-mount-path>
$ docker save <image-id> > <local-mount-path>/myImage.tar

I want to move all images with tags.

```
OUT=$(docker images --format '{{.Repository}}:{{.Tag}}')
OUTPUT=($OUT)
docker save $(echo "${OUTPUT[*]}") -o /dir/images.tar
``` 

Explanation:

First OUT gets all tags but separated with new lines. Second OUTPUT gets all tags in an array. Third $(echo "${OUTPUT[*]}") puts all tags for a single docker save command so that all images are in a single tar.

Additionally, this can be zipped using gzip. On target, run:

tar xvf images.tar.gz -O | docker load

-O option to tar puts contents on stdin which can be grabbed by docker load.


Script to perform Docker save and load function (tried and tested):

Docker Save:

#!/bin/bash

#files will be saved in the dir 'Docker_images'
mkdir Docker_images
cd Docker_images
directory=`pwd`
c=0
#save the image names in 'list.txt'
doc= docker images | awk '{print $1}' > list.txt
printf "START \n"
input="$directory/list.txt"
#Check and create the image tar for the docker images
while IFS= read -r line
do
     one=`echo $line | awk '{print $1}'`
     two=`echo $line | awk '{print $1}' | cut -c 1-3`
     if [ "$one" != "<none>" ]; then
             c=$((c+1))
             printf "\n $one \n $two \n"
             docker save -o $two$c'.tar' $one
             printf "Docker image number $c successfully converted:   $two$c \n \n"
     fi
done < "$input"

Docker Load:

#!/bin/bash

cd Docker_images/
directory=`pwd`
ls | grep tar > files.txt
c=0
printf "START \n"
input="$directory/files.txt"
while IFS= read -r line
do
     c=$((c+1))
     printf "$c) $line \n"
     docker load -i $line
     printf "$c) Successfully created the Docker image $line  \n \n"
done < "$input"

참고URL : https://stackoverflow.com/questions/23935141/how-to-copy-docker-images-from-one-host-to-another-without-using-a-repository

반응형