docker image 백업 복구

docker command : docker save & docker load

  • 백업할 docker image name 를 확인 합니다. 
[root@centos-docker ftp-service]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
b27a0fcf0969        ssh-server          "/usr/sbin/sshd -D"      2 minutes ago       Up 2 minutes        0.0.0.0:22222->22/tcp                                      ssh-server
1a1af135eebc        pure-ftpd           "/bin/sh -c '/usr/sb…"   2 minutes ago       Up 2 minutes        0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp   ftpd
[root@centos-docker ftp-service]#

 

  • docker save 명령어로 image 를 백업 합니다.
[root@centos-docker ftp-service]# docker save -o ssh-server.tar ssh-server
[root@centos-docker ftp-service]# docker save -o pure-ftpd.tar pure-ftpd

 

  • docker-compose 디렉토리를 백업합니다.
[root@centos-docker ftp-service]# cd ..
anaconda-ks.cfg  ftp-service 
[root@centos-docker ~]# tar cvf ftp-service.tar ftp-service/
ftp-service/
ftp-service/ssh-server/
ftp-service/ssh-server/Dockerfile
ftp-service/docker-compose.yml
ftp-service/pure-ftpd/
ftp-service/pure-ftpd/Dockerfile
ftp-service/pure-ftpd/pureftpd.passwd
ftp-service/ssh-server.tar
ftp-service/pure-ftpd.tar
[root@centos-docker ~]#

 

  • docker image 복구 (scp 나 ftp 를 이용하여 복구할 시스템에서 ftp-service.tar 파일을 복사해옵니다.)
[root@centos74-docker02 ~]# scp root@192.168.1.23:/root/ftp-service.tar .
[root@centos74-docker02 ~]# tar xvf ftp-service.tar
[root@centos74-docker02 ~]# cd ftp-service/

 

  • docker load 명령어를 이용하여 docker image 를 load 합니다.
[root@centos74-docker02 ftp-service]# docker load -i ssh-server.tar
aa54c2bc1229: Loading layer [==================================================>]  121.6MB/121.6MB
7dd604ffa87f: Loading layer [==================================================>]  15.87kB/15.87kB
2f0d1e8214b2: Loading layer [==================================================>]  11.78kB/11.78kB
297fd071ca2f: Loading layer [==================================================>]  3.072kB/3.072kB
4f78d015fcfa: Loading layer [==================================================>]  5.632kB/5.632kB
5b2e491f227c: Loading layer [==================================================>]  104.2MB/104.2MB
0e6f6b46199d: Loading layer [==================================================>]  3.072kB/3.072kB
Loaded image: ssh-server:latest
[root@centos74-docker02 ftp-service]# docker load -i pure-ftpd.tar
eef560b4ec4f: Loading layer [==================================================>]    197MB/197MB
11a0c2f551fd: Loading layer [==================================================>]  209.9kB/209.9kB
dda5ec330bd9: Loading layer [==================================================>]  7.168kB/7.168kB
5f96fa66dc12: Loading layer [==================================================>]  3.072kB/3.072kB
5e158c9ee888: Loading layer [==================================================>]  5.632kB/5.632kB
df1e500aba99: Loading layer [==================================================>]  210.5MB/210.5MB
f97cf7fc54cb: Loading layer [==================================================>]  13.94MB/13.94MB
d622b75b6850: Loading layer [==================================================>]  5.637MB/5.637MB
f1f64220d033: Loading layer [==================================================>]  10.75kB/10.75kB
93a7b057a761: Loading layer [==================================================>]  4.293MB/4.293MB
34e855b6a251: Loading layer [==================================================>]  582.7kB/582.7kB
44de25e21a3f: Loading layer [==================================================>]  379.4kB/379.4kB
62f4467edb00: Loading layer [==================================================>]  3.584kB/3.584kB
3b53068e8e0f: Loading layer [==================================================>]   5.12kB/5.12kB
6a75a4844f83: Loading layer [==================================================>]  3.072kB/3.072kB
Loaded image: pure-ftpd:latest
[root@centos74-docker02 ftp-service]#

 

  • docker image 를 확인 합니다.
  • docker-compose 를 실행 합니다.
[root@centos74-docker02 ftp-service]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              286889354875        27 minutes ago      217MB
pure-ftpd           latest              50a17f653588        28 minutes ago      415MB
[root@centos74-docker02 ftp-service]#
[root@centos74-docker02 ftp-service]# docker-compose up -d
Creating ssh-server ... done
Creating ftpd       ... done
[root@centos74-docker02 ftp-service]#

 

  • 서비스 확인을 진행 합니다.

 

Docker 로 pure-ftpd 를 개인적으로 운영하고 있습니다.

사용자가 적을 경우 문제가 없지만 보안상의 이유 및 특정 디렉토리 변경 되는 이슈 때문에 아주 간단한 방법으로

ftp user 권한을 변경할까 합니다.

docker-compose 내용은 일전에 올려 놓은 포스트를 참고해 주세요.

링크는 아래 있습니다. 🙂

[docker] docker-compose pure-ftpd ssh-server구성

 

  • 디렉토리 권한 변경 
#ftp Directory 는 /ftp-data 를 사용 하고 있습니다. 
/ftp-data 를 755 권한합니다. 
# chmod -R 755 /ftp-data

 

  • pure-ftpd/Dockerfile 수정
[root@centos-docker ftp-service]# ll
total 4
-rw-rw-r-- 1 test01 test01 647 Mar  3  2017 docker-compose.yml
drwxrwxr-x 2 test01 test01  47 Apr 23 20:04 pure-ftpd
drwxrwxr-x 2 test01 test01  24 Apr 22 20:00 ssh-server
[root@centos-docker ftp-service]#

[root@centos-docker ftp-service]# cat pure-ftpd/Dockerfile
FROM ubuntu:14.04

MAINTAINER test@test.com

RUN sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
RUN apt-get update && \
apt-get install pure-ftpd openssl libpam-dev libcap2-dev libldap2-dev libmysqlclient-dev libmysqlclient15-dev libpq-dev libssl-dev po-debconf dpkg-dev debhelper -y

RUN mkdir /tmp/pure-ftpd/ && \
        cd /tmp/pure-ftpd/ && \
        apt-get source pure-ftpd && \
        cd pure-ftpd-* && \
        sed -i '/^optflags=/ s/$/ --without-capabilities/g' ./debian/rules && \
        dpkg-buildpackage -b -uc
RUN dpkg -i /tmp/pure-ftpd/pure-ftpd-common*.deb
RUN apt-get -y install openbsd-inetd
RUN dpkg -i /tmp/pure-ftpd/pure-ftpd_*.deb
RUN apt-mark hold pure-ftpd pure-ftpd-common
RUN cd /etc/pure-ftpd && \
adduser ftpd-data && \
adduser ftpd-users && \          <-- 라인추가

 

  • docker-compose 실행 
[root@centos-docker ftp-service]# docker-compose up -d --build

 

  • pure-ftpd 유저 생성 및 password 생성 
[root@centos-docker ftp-service]# docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
417c5aee93e3        ssh-server               "/usr/sbin/sshd -D"      33 minutes ago      Up 33 minutes       0.0.0.0:22222->22/tcp                                      ssh-server
73ec4613358b        private/pure-ftpd:14.04   "/bin/sh -c '/usr/sb…"   33 minutes ago      Up 33 minutes       0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp   ftpd
[root@centos-docker ftp-service]# docker
[root@centos-docker ftp-service]# docker exec -it 73ec4613358b /bin/bash

ftp user 작업 
ftpd-users 구룹은 Read Only User group 이며,
ftpd-data 구룹은  write User group 입니다. 
root@73ec4613358b:/# pure-pw useradd test01 -u ftpd-users -g ftpd-users -d /home/ftp
Password:
Enter it again:
root@73ec4613358b:/# pure-pw useradd data01 -u ftpd-data -g ftpd-data -d /home/ftp
Password:
Enter it again:
root@73ec4613358b:/# pure-pw mkdb
root@73ec4613358b:/# cat /etc/pure-ftpd/pureftpd.passwd
~중략
test01:$1$VWoNttg0$MeF4ibc.JQCdlS3BFp3rT.:1001:1001::/home/ftp/./::::::::::::
data01:$1$iP7Popf0$htP3edje8B2BptmyEe7mG0:1000:1000::/home/ftp/./::::::::::::

pureftpd.passwd 파일에 생성한 유저를 추가 합니다. 
[root@centos-docker ftp-service]# vi pure-ftpd/pureftpd.passwd


ftp 접속후 권한 테스트를 진행 합니다.