Skip to content

Instantly share code, notes, and snippets.

@practice
Last active August 29, 2015 14:10
Show Gist options
  • Save practice/7be8297ca74b6982f265 to your computer and use it in GitHub Desktop.
Save practice/7be8297ca74b6982f265 to your computer and use it in GitHub Desktop.
생활코딩 docker tutorial
http://opentutorials.org/course/128/8657
$ sudo apt-get update
$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh # Docker를 설치하자.
$ sudo docker images #이미지 목록을 살펴보자. 아무 것도 없다.
$ sudo docker pull ubuntu:14.04 # 우분투를 땡켜오자.
$ sudo docker run -i -t ubuntu:14.04 /bin/bash # 땡겨온 우분투로 bash를 실행하자.
$ # 다른 터미널로 접속해 아래와 같이 docker ps를 하면 방금 실행한 bash가 보인다. 이게 지금 컨테이너에서 실행되는 것이다.
$ sudo docker ps -a # 실행중인 컨테이너 목록을 보자. -a는 종료된 컨테이너도 보는 옵션.
$ sudo docker start goofy_brattain # goofy_brattain은 docker가 임의로 만든 컨테이너 이름이다. 이 이름으로 실행할 수도 있다. start 옵션때문에 컨테이너 안으로 들어가지 않는다.
$ sudo docker ps # 방금 실행한 goofy_brattain이 목록에 나올 것이다.
$ sudo docker attach goofy_brattain # start로 실행한 컨테이너 안으로 들어간다.
# 컨테이너 안에서 Ctrl+P,Ctrl+Q 를 누르면 컨테이너를 종료하지 않고 나옴.
$ Sudo docker stop goofy_brattain # 컨테이너 밖에서 컨테이너를 종료함.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7418b6346709 ubuntu:14.04 "/bin/bash" About an hour ago Exited (1) 5 minutes ago high_bartik
3bfedcbc189b ubuntu:14.04 "/bin/bash" About an hour ago Exited (0) About an hour ago happy_perlman
6c29a3bc669a ubuntu:14.04 "/bin/bash" About an hour ago Exited (0) 6 seconds ago goofy_brattain
$ sudo docker rm goofy_brattain # 컨테이너 삭제
goofy_brattain
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7418b6346709 ubuntu:14.04 "/bin/bash" About an hour ago Exited (1) 7 minutes ago high_bartik
3bfedcbc189b ubuntu:14.04 "/bin/bash" About an hour ago Exited (0) About an hour ago happy_perlman
# nginx를 실행해보자.
$ sudo docker pull nginx:latest # 최신버전을 땡겨 옴
nginx:latest: The image you are pulling has been verified
f10807909bc5: Pull complete
f6fab3b798be: Pull complete
ef45dc12127b: Pull complete
e426f6ef897e: Pull complete
511136ea3c5a: Already exists
Status: Downloaded newer image for nginx:latest
$ sudo docker images # 이미지 목록을 보면 nginx가 있따.
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest e426f6ef897e 11 days ago 100.2 MB
ubuntu 14.04 5506de2b643b 4 weeks ago 199.3 MB
$ sudo docker run -d --name hello-nginx nginx:latest # -d는 대몬으로 실행한다는 의미. —name 은 컨테이너에 이름을 부여함.
b0819269f4c7bb435eff001944910ab647100a22ecacf542291b4d3842bc8d04
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0819269f4c7 nginx:latest "nginx -g 'daemon of 8 seconds ago Up 8 seconds 80/tcp, 443/tcp hello-nginx
# Docker exec로 컨테이너 안에서 무언가를 실행함. 여기서는 파일을 만들어 보겠음.
$ sudo docker run -i -t --name hello ubuntu:14.04 /bin/bash # 일단 bash를 실행하고…
root@d4678636a18e:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
shawn@stackdev:~$ # Ctrl+P, Ctrl+Q로 나온 다음.
shawn@stackdev:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d4678636a18e ubuntu:14.04 "/bin/bash" 13 seconds ago Up 13 seconds hello
b0819269f4c7 nginx:latest "nginx -g 'daemon of 5 minutes ago Up 5 minutes 443/tcp, 80/tcp hello-nginx
$ sudo docker exec hello echo 1
1
$ sudo docker exec hello touch /hello.txt # docker exec로 파일을 만듦
$ ls / # 밖에는 파일이 없음.
bin dev home initrd.img.old lib64 media opt proc run srv tmp var vmlinuz.old
boot etc initrd.img lib lost+found mnt play root sbin sys usr vmlinuz
$ sudo docker exec hello ls / # 파일이 보임.
… hello.txt …
$ sudo docker attach hello # 컨테이너 안으로 들어가서 확인해보면…
root@d4678636a18e:/# ls
bin boot dev etc hello.txt home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment