Ubuntu 환경에서 Docker 설치를 조금은 색다르게 해보고자 한다.

 

여러 편한 방법이 있겠지만, 직접 버전을 선택해서 패키지 파일을 내려 받아 설치하는 것이다.

특정 버전을 직접 관리하면서 사용할 수 있다는 장점이 있다.

 

 

1. Ubuntu 버전 확인

  - 지금 사용하고 있는 버전이 어떤 것인지 확인을 해보자.

 

❯ lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal

 

 

2. Docker 패키지 파일 확인

  - 어떤 버전이 있는지, 그리고 다운로드 주소가 어떻게 되는지 확인 해보자.

    . https://download.docker.com/linux/ubuntu/dists/

 

 

  - 우리가 확인해야할 패키지는 다음의 3 종류이다.

    . containerd

    . docker-ce-cli

    . docker-ce

 

 

3. 패키지 다운로드 및 설치

  - 이제 내려받아서 설치하자.

 

❯ wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/containerd.io_1.6.21-1_amd64.deb
❯ wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce-cli_23.0.6-1~ubuntu.20.04~focal_amd64.deb
❯ wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce_23.0.6-1~ubuntu.20.04~focal_amd64.deb

❯ sudo dpkg --install ./containerd.io_1.6.21-1_amd64.deb
❯ sudo dpkg --install ./docker-ce-cli_23.0.6-1~ubuntu.20.04~focal_amd64.deb
❯ sudo dpkg --install ./docker-ce_23.0.6-1~ubuntu.20.04~focal_amd64.deb

 

 

4. 실행 권한 설정

  - root가 아닌 현재 사용자 계정에서 docker를 사용하기 위해 그룹 설정을 해주자.

 

❯ sudo usermod -aG docker $USER

 

  - 설정한 다음, 재부팅 또는 로그 오프 후 재로그인을 해줘야 한다.

  - 그리고 잘 되는지 확인해보자.

 

❯ docker --version

Docker version 23.0.6, build ef23cbc

 

 

5. 실습을 위한 파일 작성

  - docker build 실습을 위한 파일 2개를 다음과 같이 준비하자.

 

❯ nano index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Kubernetes</title>
</head>
<body>
  <h2>Hello, This is K8s World</h2>
</body>
</html>

 

❯ nano Dockerfile

FROM nginx:latest

COPY ./index.html /usr/share/nginx/html/index.html

 

 

6. docker build

  - 이미지 생성해보자.

  - 마지막에 . 찍어주는 것 잊지 말자 ^^

 

❯ docker build -t webserver .

DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM nginx:latest
latest: Pulling from library/nginx
9e3ea8720c6d: Pull complete 
bf36b6466679: Pull complete 
15a97cf85bb8: Pull complete 
9c2d6be5a61d: Pull complete 
6b7e4a5c7c7a: Pull complete 
8db4caa19df8: Pull complete 
Digest: sha256:480868e8c8c797794257e2abd88d0f9a8809b2fe956cbfbc05dcc0bca1f7cd43
Status: Downloaded newer image for nginx:latest
 ---> 448a08f1d2f9
Step 2/2 : COPY ./index.html /usr/share/nginx/html/index.html
 ---> 32317f8e7b5c
Successfully built 32317f8e7b5c
Successfully tagged webserver:latest

 

  - 응?! DEPRECATED ?! BuildKit을 사용해야 한단다.

 

 

7. BuildKit 설치

  - docker 패키지 살펴볼 때 눈치 빠르신 분은 이미 찾았을 것이다.

 

 

❯ wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-buildx-plugin_0.10.4-1~ubuntu.20.04~focal_amd64.deb

❯ sudo dpkg --install ./docker-buildx-plugin_0.10.4-1~ubuntu.20.04~focal_amd64.deb

 

 

 

8 docker buildx build

  - 이제 새롭게 빌드해보자. 명령어는 크게 다르지 않다.

 

❯ docker buildx build -t webserver2 .

[+] Building 0.4s (7/7) FINISHED                                                                                                                                
 => [internal] load build definition from Dockerfile                                                                                                       0.1s
 => => transferring dockerfile: 107B                                                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                                                  0.1s
 => => transferring context: 2B                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/nginx:latest                                                                                      0.0s
 => [internal] load build context                                                                                                                                   0.1s
 => => transferring context: 199B                                                                                                                                0.0s
 => [1/2] FROM docker.io/library/nginx:latest                                                                                                              0.2s
 => [2/2] COPY ./index.html /usr/share/nginx/html/index.html                                                                                     0.1s
 => exporting to image                                                                                                                                                 0.1s
 => => exporting layers                                                                                                                                                0.1s
 => => writing image sha256:3f0130968d1e78db17dc061d1363da5f49c8157a1a73ffb10d923d9d7af16af               0.0s
 => => naming to docker.io/library/webserver2 

 

여기까지~

 

 

간만에 docker build 해봤다가 명령어가 deprecated 되었다고 해서 깜짝 놀라 급히 정리해봤다 ^^

 

 

반응형


1. 필수 패키지 설치

$ sudo apt-get install make libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto autoconf

 

 

2. 다운로드

$ cd /srv/install/git

$ wget http://git-core.googlecode.com/files/git-1.8.4.1.tar.gz
$ tar zxvf git-1.8.4.1.tar.gz
$ cd git-1.8.4.1/


3. 빌드

$ make configure
$ ./configure --prefix=/usr/local
$ make all doc
$ sudo make install install-doc install-html

   - 설치가 잘 되었는지 확인을 해보기 위해서 버전 확인을 해보자.

$ git --version



GIT 자동완성을 지원하기 위해서는...
   - http://whatwant.tistory.com/478


우리 모두 Git으로 행복한 형상관리를...


반응형

Linux 환경에서 build (compile) 시간을 짧게하기 위한 방법을 찾아보면 꼭 나오는 방법이 있다.
바로 ccachedistcc 다!

여기에서는 ccache에 대해서 알아보겠다.

원리는 비교적 간단하다.
처음에 빌드를 할 때에 정보와 함께 그 결과물을 저장하고 있다가,
다음 번 빌드를 할 때엔 정보를 비교해서 같은 파일의 빌드를 한다면 저장하고 있는 결과물을 활용하는 것이다.
그렇게 함으로써 두 번째 빌드부터는 변경된 부분만 빌드를 수행하므로 소요시간이 짧아지는 것이다.




1. 공식 사이트

     - http://ccache.samba.org/
     - License : GPL3

     - 기본적으로 gcc 컴파일에 적용을 할 수 있으며, Cross-compiler (Tool-chain)에도 적용할 수 있다.

     - 안전성에 대해서는 나름 자부를 하고 있는 상당히 오래된 프로젝트이며,
       구글의 안드로이드에서도 공식적으로 옵션으로 적용을 하고 있다.




2. Install

     - Ubuntu에서는 편하게 패키지로 제공을 해준다.


$ sudo apt-get install ccache

     - 이걸로 끝이다. 간단하지 않은가 ?!




3. PATH

     - ccache를 활용하기 위해서는 PATH 설정만 해주면 된다.


$ sudo nano /etc/environment

PATH="/usr/lib/ccache:......."

     - 환경파일에서 PATH 값에서 제일 앞에 "/usr/lib/ccache:" 경로를 추가해주면 된다.
     - 일단은 이러면 끝이다.




4. Environment

     - 그러면 대체 왜 "/usr/lib/ccache" 디렉토리를 경로에 추가를 해줘야할까?


$ cd /usr/lib/ccache

     - 검색해서 자료들을 보면 "export CC='ccache cc'"등을 설정하기도 하고,
       Makefile을 수정하기도 하는 등 다른 방식으로 처리하기도 하지만...
     - 최근엔 그냥 '/usr/lib/ccache' 디렉토리를 이용하면 모든 것이 끝이다.

     - Compiler를 모두 ccache로 대체하면 되는 것이다.

     - 만약 Cross-compiler (Tool-chain)을 사용하는 경우라면 위 디렉토리에 링크를 만들어주면 된다.

$ cd /usr/lib/ccache
$ sudo ln -s ../../bin/ccache powerpc-tuxbox-linux-gnu-cc
$ sudo ln -s ../../bin/ccache powerpc-tuxbox-linux-gnu-c++
$ sudo ln -s ../../bin/ccache powerpc-tuxbox-linux-gnu-gcc
$ sudo ln -s ../../bin/ccache powerpc-tuxbox-linux-gnu-g++






5. cache dir

     - ccache를 적용하면 빌드 결과물을 어딘가에 저장해놓는다고 했는데, 어디에 위치할까?


$ ccache -s

     - 상태(status)를 확인하고 싶을 때 사용할 수 있는 명령이다.

     - 기본적으로는 홈 밑의 ".ccache" 디렉토리에 위치하며, 기본 용량제한은 1GB이다.





6. clear

     - 빌드 결과가 왠지 이상하다거나 cache 데이터를 지우고 싶을 때엔 다음 명령으로 처리할 수 있다.


$ ccache -C




몇 가지 더 옵션들이 있지만, 알고 싶으면 공식 사이트를 참조하기 바란다.
실제로 적용해보면 탁월하게 효과가 있다~!!!

반응형

+ Recent posts