새소식

인기 검색어

Docker

6/30 컨테이너

  • -

베어메탈 -> 버츄얼머신 -> 컨테이너

ring 0 : 커널 (가장 권한 많음)

ring 3: 어플리케이션(실행할 프로그램)

 


(base) student@cccr:~/vagrant$ mkdir docker
(base) student@cccr:~/vagrant$ cd docker
(base) student@cccr:~/vagrant/docker$ cp ~/vagrant/wp/Vagrantfile .
(base) student@cccr:~/vagrant/docker$ vi Vagrantfile
(base) student@cccr:~/vagrant/docker$ ls
Vagrantfile
(base) student@cccr:~/vagrant/docker$ code Vagrantfile 
(base) student@cccr:~/vagrant/docker$ vagrant up
Bringing machine 'docker' up with 'virtualbox' provider...
==> docker: Importing base box 'ubuntu/focal64'...
==> docker: Matching MAC address for NAT networking...
==> docker: Checking if box 'ubuntu/focal64' version '20210624.0.0' is up to date...
==> docker: Setting the name of the VM: docker
==> docker: Clearing any previously set network interfaces...
==> docker: Preparing network interfaces based on configuration...
    docker: Adapter 1: nat
    docker: Adapter 2: hostonly
==> docker: Forwarding ports...
    docker: 22 (guest) => 2222 (host) (adapter 1)
==> docker: Running 'pre-boot' VM customizations...
==> docker: Booting VM...
==> docker: Waiting for machine to boot. This may take a few minutes...
    docker: SSH address: 127.0.0.1:2222
    docker: SSH username: vagrant
    docker: SSH auth method: private key
    docker: Warning: Connection reset. Retrying...
    docker: Warning: Remote connection disconnect. Retrying...
    docker: 
    docker: Vagrant insecure key detected. Vagrant will automatically replace
    docker: this with a newly generated keypair for better security.
    docker: 
    docker: Inserting generated public key within guest...
    docker: Removing insecure key from the guest if it's present...
    docker: Key inserted! Disconnecting and reconnecting using new SSH key...
==> docker: Machine booted and ready!
==> docker: Checking for guest additions in VM...
==> docker: Setting hostname...
==> docker: Configuring and enabling network interfaces...
==> docker: Mounting shared folders...
    docker: /vagrant => /home/student/vagrant/docker
(base) student@cccr:~/vagrant/docker$ 

https://docs.docker.com/engine/install/ubuntu/

 

Install Docker Engine on Ubuntu

 

docs.docker.com

이대로 설치해보기

 

(base) student@cccr:~$ cd vagrant/docker
(base) student@cccr:~/vagrant/docker$ vagrant up
Bringing machine 'docker' up with 'virtualbox' provider...
==> docker: Checking if box 'ubuntu/focal64' version '20210624.0.0' is up to date...
==> docker: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> docker: flag to force provisioning. Provisioners marked to run always will still run.
(base) student@cccr:~/vagrant/docker$ vagrant ssh docker
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-77-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Jun 30 05:08:42 UTC 2021

  System load:  0.0               Processes:               120
  Usage of /:   3.2% of 38.71GB   Users logged in:         0
  Memory usage: 5%                IPv4 address for enp0s3: 10.0.2.15
  Swap usage:   0%                IPv4 address for enp0s8: 192.168.200.30

 * Super-optimized for small spaces - read how we shrank the memory
   footprint of MicroK8s to make it the smallest full K8s around.

   https://ubuntu.com/blog/microk8s-memory-optimisation

1 update can be applied immediately.
To see these additional updates run: apt list --upgradable


vagrant@docker:~$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [741 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [8628 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [7960 B]
Get:8 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [628 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [95.9 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [11.6 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [19.9 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [4316 B]
Get:13 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [528 B]
Get:14 http://archive.ubuntu.com/ubuntu focal/universe Translation-en [5124 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [144 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal/multiverse Translation-en [104 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9136 B]
Get:19 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1081 kB]
Get:20 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en [238 kB]
Get:21 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [13.6 kB]
Get:22 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [318 kB]
Get:23 http://archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [46.1 kB]
Get:24 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [827 kB]
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [173 kB]
Get:26 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [17.9 kB]
Get:27 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [23.6 kB]
Get:28 http://archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [6472 B]
Get:29 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [648 B]
Get:30 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [112 B]
Get:31 http://archive.ubuntu.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]
Get:32 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [4032 B]
Get:33 http://archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [1448 B]
Get:34 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [224 B]
Get:35 http://archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 18.9 MB in 12s (1619 kB/s)                                             
Reading package lists... Done
Building dependency tree       
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
vagrant@docker:~$ cudo -i

Command 'cudo' not found, did you mean:

  command 'cdo' from deb cdo (1.9.9~rc1-1)
  command 'sudo' from deb sudo (1.8.31-1ubuntu1.2)
  command 'sudo' from deb sudo-ldap (1.8.31-1ubuntu1.2)
  command 'udo' from deb udo (6.4.1-5)
  command 'cuyo' from deb cuyo (2.0.0brl1-3build2)

Try: apt install <deb name>

vagrant@docker:~$ sudo -i
root@docker:~# cd apt/
-bash: cd: apt/: No such file or directory
root@docker:~# mkdir apt
root@docker:~# cd apt/
root@docker:~/apt# cd~

Command 'cd~' not found, did you mean:

  command 'cdw' from deb cdw (0.8.1-1build4)
  command 'cdi' from deb cdo (1.9.9~rc1-1)
  command 'cd5' from deb cd5 (0.1-4)
  command 'cde' from deb cde (0.1+git9-g551e54d-1.1build1)
  command 'cdp' from deb irpas (0.10-7)
  command 'cdb' from deb tinycdb (0.78build1)
  command 'cdo' from deb cdo (1.9.9~rc1-1)

Try: apt install <deb name>

root@docker:~/apt# cd ..
root@docker:~# exit
logout
vagrant@docker:~$ sudo -i
root@docker:~# cd /etc
root@docker:/etc# cd apt
root@docker:/etc/apt# ls
apt.conf.d  auth.conf.d  preferences.d  sources.list  sources.list.d  trusted.gpg.d
root@docker:/etc/apt# cd trusted.gpg.d/
root@docker:/etc/apt/trusted.gpg.d# ls
ubuntu-keyring-2012-archive.gpg  ubuntu-keyring-2018-archive.gpg
ubuntu-keyring-2012-cdimage.gpg
root@docker:/etc/apt/trusted.gpg.d# pwd
/etc/apt/trusted.gpg.d
root@docker:/etc/apt/trusted.gpg.d# cd ..
root@docker:/etc/apt# cd ..
root@docker:/etc# cd ..
root@docker:/# cd ..
root@docker:/# sudo apt-get install \
> apt-transport-https \
> ca-certificates \
> curl \
> gnupg \
> lsb-release
Reading package lists... Done
Building dependency tree       
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20210119~20.04.1).
ca-certificates set to manually installed.
curl is already the newest version (7.68.0-1ubuntu2.5).
curl set to manually installed.
gnupg is already the newest version (2.2.19-3ubuntu2.1).
gnupg set to manually installed.
The following NEW packages will be installed:
  apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 1704 B of archives.
After this operation, 161 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.5 [1704 B]
Fetched 1704 B in 1s (2349 B/s)               
Selecting previously unselected package apt-transport-https.
(Reading database ... 63206 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.0.5_all.deb ...
Unpacking apt-transport-https (2.0.5) ...
Setting up apt-transport-https (2.0.5) ...

root@docker:/# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
root@docker:/# echo \
>   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
>   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
root@docker:/# sudo apt-get update
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [52.1 kB]
Get:2 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [9960 B]        
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease                                     
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease                         
Hit:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Fetched 62.1 kB in 1s (54.3 kB/s)
Reading package lists... Done
root@docker:/# sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz
  slirp4netns
0 upgraded, 7 newly installed, 0 to remove and 2 not upgraded.
Need to get 108 MB of archives.
After this operation, 466 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.4.6-1 [28.3 MB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]    
Get:3 http://archive.ubuntu.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.7~3-0~ubuntu-focal [41.4 MB]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.7~3-0~ubuntu-focal [24.8 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.7~3-0~ubuntu-focal [9063 kB]
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.8.0~ubuntu-focal [3889 kB]

root@docker:/# apt-cache madison docker-ce
 
root@docker:/# sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
-bash: VERSION_STRING: No such file or directory
root@docker:/# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

vagrant@docker:~$ sudo ls -l /var/run/docker.sock        -> 소켓파일(이 파일에 접근하면 도커 대문에 접근하는거나 마찬가지)
srw-rw---- 1 root docker 0 Jun 30 05:29 /var/run/docker.sock

vagrant@docker:~$ id -a
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant)
vagrant@docker:~$ sudo usermod -aG docker vagrant  -> vagrant 라는 사용자를 도커그룹에 속하게 한다

vagrant@docker:~$ exit
logout
Connection to 127.0.0.1 closed.
(base) student@cccr:~/vagrant/docker$ vagrant ssh
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-77-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Jun 30 06:02:42 UTC 2021

  System load:  0.13              Users logged in:          0
  Usage of /:   5.0% of 38.71GB   IPv4 address for docker0: 172.17.0.1
  Memory usage: 7%                IPv4 address for enp0s3:  10.0.2.15
  Swap usage:   0%                IPv4 address for enp0s8:  192.168.200.30
  Processes:    116

 * Super-optimized for small spaces - read how we shrank the memory
   footprint of MicroK8s to make it the smallest full K8s around.

   https://ubuntu.com/blog/microk8s-memory-optimisation

2 updates can be applied immediately.
To see these additional updates run: apt list --upgradable


Last login: Wed Jun 30 05:08:42 2021 from 10.0.2.2
vagrant@docker:~$ docker ps            -> 현재 실행중인 컨테이너의 목록 확인(뒤에 -a 붙여서 확인 가능)
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
vagrant@docker:~$ docker run hello-world    -> 헬로우 월드라는 이미지 이름을 실행해라
vagrant@docker:~$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB

https://hub.docker.com/_/hello-world

 

hello-world

We and third parties use cookies or similar technologies ("Cookies") as described below to collect and process personal data, such as your IP address or browser information. You can learn more about how this site uses Cookies by reading our privacy policy

hub.docker.com


vagrant@docker:~$ echo $?      -> 방금전에 실행했던 종료코드 확인(0을 제외한 나머지 숫자는 비정상 코드)
0

 

vagrant@docker:~$ docker run -d httpd           -> 백그라운드 실행(내가 종료하기 전까지 계속 실행)
2541036ee39da2552bc8cb33695059909763d5d959c8c4c032288aad9d96add9

'Docker' 카테고리의 다른 글

도커 볼륨  (0) 2021.07.01
컨테이너 실행  (0) 2021.07.01
7/1 컨테이너 실행  (0) 2021.07.01
7/1 Docker 이미지 다운로드/업로드  (0) 2021.07.01
6/28 vagrantfile 작성 및 haproxy, 스토리지 구성  (0) 2021.06.28
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.