1. docker run

로컬에서 ubuntu 이미지가 없어서 다운로드를 받았지만,

$ docker run ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
898c46f3b1a1: Pull complete
63366dfa0a50: Pull complete
041d4cd74a92: Pull complete
6e1bee0f8701: Pull complete
Digest: sha256:017eef0b616011647b269b5c65826e2e2ebddbe5d1f8c1e56b3599fb14fabec8
Status: Downloaded newer image for ubuntu:latest
$

딱히 실행되는 것 없이? 그냥 멈춤.

다시 docker run 실행

$ docker run ubuntu
$

이번에는 /bin/bash 추가하여 docker run 실행

$ docker run ubuntu /bin/bash
$

이번에는 -it 옵션도 추가하여 docker run 실행

$ docker run -it ubuntu /bin/bash
root@d3577bf9b8d9:/#

docker 안에서 뭔가 해보자.

root@d3577bf9b8d9:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
root@d3577bf9b8d9:/#

good.

이제 docker에서 나가보자.

root@d3577bf9b8d9:/# exit
exit
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
d3577bf9b8d9        ubuntu              "/bin/bash"         5 minutes ago       Exited (0) 3 seconds ago                          heuristic_hypatia

docker ps -a 했더니 이름은 heuristic_hypatia라고 알아서 지어졌고, 5분 전에 만들어서 3초 전에 나왔다고 한다.

2.  docker start

이제 아까 나온 docker에 다시 들어가보자.

$ docker start -i heuristic_hypatia
root@d3577bf9b8d9:/#

간단히 텍스트 파일을 만들고 다시 나올려고 한다.

root@d3577bf9b8d9:/# pwd
/
root@d3577bf9b8d9:/# echo "Docker Docker" > docker.txt
root@d3577bf9b8d9:/# cat docker.txt
Docker Docker
root@d3577bf9b8d9:/# exit
exit
$

다시 docker start해서 들어감.

$ docker start -i heuristic_hypatia
root@d3577bf9b8d9:/# pwd
/
root@d3577bf9b8d9:/# cat docker.txt
Docker Docker
root@d3577bf9b8d9:/#

파일이 살아있다.