docker commiit에 메모
13344 단어 Docker
컨디션
CentOS 6.5 on VirtualBox
Docker 설치
# yum install docker-io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tsukuba.wide.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* updates: centos.tt.co.kr
Setting up Install Process
No package docker-io available.
Error: Nothing to do
document에 따라 EPEL을 넣고 다시 테스트# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Retrieving http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.SXgnRV: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
# yum install docker-io
# docker -v
Docker version 1.3.2, build 39fa2fa/1.3.2
# service docker start
Starting cgconfig service: [ OK ]
Starting docker: [ OK ]
루트 사용자로 컨테이너 만들기
이 일대 알기 쉽다.결과적으로 후술한 작업 중 일반 사용자에게 허가 이하의 작업이 가장 좋다고 느꼈다.
# docker run centos /bin/echo "hello world"
Unable to find image 'centos' locally
centos:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
5b12ef8fd570: Pull complete
34943839435d: Pull complete
Status: Downloaded newer image for centos:latest
hello world
# docker run centos /bin/cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
움직였어. pull Docker Hub의 인상을
# docker pull centos:centos6
# docker run centos:centos6 /bin/cat /etc/redhat-release
CentOS release 6.6 (Final)
컨테이너 시작
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos6 25c5298b1a36 2 weeks ago 215.8 MB
centos latest 34943839435d 2 weeks ago 224 MB
# docker run --name="intro" -t -i -d 25c5 /bin/bash
722f3a7dad6897d9749ac93b979ae8d8c420220af8728bc326cc76f32ae857aa
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
722f3a7dad68 centos:centos6 "/bin/bash" 14 seconds ago Up 13 seconds intro
# docker attach 722f3a7dad68
[root@722f3a7dad68 /]#
변경 내용 저장
변경을 가하다.예를 들어 사용자를 추가하려고 시도하다.
[root@722f3a7dad68 /]# useradd myuser
[root@722f3a7dad68 /]# tail -1 /etc/passwd
myuser:x:500:500::/home/myuser:/bin/bash
detachCTRL-p
+CTRL-q
).아니오exit
.그 후commit
.# docker commit -m "useradd" 722f3a7dad68 mycontainer
4d15b0eac3b0f2e41b607fef77b6bccf507f709cf8d4453d6e8c44e20e4a877a
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mycontainer latest 4d15b0eac3b0 47 seconds ago 215.9 MB
centos centos6 25c5298b1a36 2 weeks ago 215.8 MB
centos latest 34943839435d 2 weeks ago 224 MB
새 이미지가 생성되었습니다4d15b0eac3b0
.이름이 너무 잘 어울려요?변경 사항을 저장하지 않는 경우
다시
attach
사용자 한 명을 추가합니다.[root@722f3a7dad68 /]# useradd myuser2
[root@722f3a7dad68 /]# tail -2 /etc/passwd
myuser:x:500:500::/home/myuser:/bin/bash
myuser2:x:501:501::/home/myuser2:/bin/bash
저장된 이미지부터 컨테이너 시작# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
722f3a7dad68 centos:centos6 "/bin/bash" 50 minutes ago Up 50 minutes intro
# docker run --name="intro2" -t -i -d 4d /bin/bash
4942e5a4d043209032b0c2e76d6cbadfbc3d63f5b6bfaa2e4cf5dda6108d8997
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4942e5a4d043 mycontainer:latest "/bin/bash" 13 seconds ago Up 12 seconds intro2
722f3a7dad68 centos:centos6 "/bin/bash" 52 minutes ago Up 51 minutes intro
# docker attach 49
[root@4942e5a4d043 /]# tail -2 /etc/passwd
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
myuser:x:500:500::/home/myuser:/bin/bash
저장된 변경 점에서 다시 시작합니다.(저장 후 두 번째 사용자가 추가하지 않음)난리가 나서 컨테이너를 정리하는 거예요.
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4942e5a4d043 mycontainer:latest "/bin/bash" 5 minutes ago Up 5 minutes intro2
722f3a7dad68 centos:centos6 "/bin/bash" 56 minutes ago Up 56 minutes intro
# docker stop 4942e5a4d043
4942e5a4d043
# docker stop 722f3a7dad68
722f3a7dad68
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
stop
도 보유rm
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4942e5a4d043 mycontainer:latest "/bin/bash" 14 minutes ago Exited (-1) 8 minutes ago intro2
722f3a7dad68 centos:centos6 "/bin/bash" About an hour ago Exited (-1) 8 minutes ago intro
# docker rm 4942e5a4d043
4942e5a4d043
# docker rm 722f3a7dad68
722f3a7dad68
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
이미지 정리
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mycontainer latest 4d15b0eac3b0 50 minutes ago 215.9 MB
centos centos6 25c5298b1a36 2 weeks ago 215.8 MB
centos latest 34943839435d 2 weeks ago 224 MB
# docker rmi 4d15b0eac3b0
Untagged: mycontainer:latest
Deleted: 4d15b0eac3b0f2e41b607fef77b6bccf507f709cf8d4453d6e8c44e20e4a877a
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos6 25c5298b1a36 2 weeks ago 215.8 MB
centos latest 34943839435d 2 weeks ago 224 MB
일반 사용자 해보세요.
본보기document, 일반 사용자 추가
docker
$ sudo usermod -a -G docker satzz
$ sudo vi /etc/sysconfig/docker
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d
#other_args=
other_args="-H 127.0.0.1:4243" # add
$ export DOCKER_HOST=tcp://127.0.0.1:4243
$ docker pull centos:centos6
centos:centos6: The image you are pulling has been verified
511136ea3c5a: Already exists
5b12ef8fd570: Already exists
25c5298b1a36: Already exists
Status: Image is up to date for centos:centos6
기존의 인상을 사용할 수 있다.DOCKER_HOST
는 .bashrc
등에 써야 한다.$ docker run --name="intro" -t -i -d 25c5 /bin/bash
0c890bd6d900ae4cc609fb85b7ea36ba91b93bd96bd8c6628f8aa717b4dcdd2c
$ docker attach 0c890bd6d900ae4cc609fb85b7ea36ba91b93bd96bd8c6628f8aa717b4dcdd2c
[root@0c890bd6d900 /]#
run
와attach
도 가능합니다.detach가 아니라 exit면 어떨까.
$ docker run --name="intro" -t -i -d 25c5 /bin/bash
3b2d8ffaaac414f3a5e96fddb2ff7303be8c6db5a615cca2f81b9cabde2d7410
$ docker attach 3b2d8ffaaac414f3a5e96fddb2ff7303be8c6db5a615cca2f81b9cabde2d7410
[root@3b2d8ffaaac4 /]# exit
exit
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b2d8ffaaac4 centos:centos6 "/bin/bash" 15 seconds ago Exited (0) 3 seconds ago intro
$ docker attach 3b2d8ffaaac4
2014/12/18 18:49:59 You cannot attach to a stopped container, start it first
STATUS
는UP
Exited
이다.이동이 없어서 attach
할 수 없지만 start
하면 attach
할 수 있어요.$ docker start 3b2d8ffaaac4
3b2d8ffaaac4
$ docker attach 3b2d8ffaaac4
[root@3b2d8ffaaac4 /]#
Reference
이 문제에 관하여(docker commiit에 메모), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/satzz/items/642db69da9852522e6c9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)