'Cloud&Container/IaC'에 해당되는 글 16건

  1. 2022.03.24 [Docker] apk not found 또는 certificate verify failed:ssl 발생 시.
  2. 2021.07.14 [Docker] 로컬에 MySQL 설치 합니다.
  3. 2021.02.01 [Docker] ARG 와 ENV 사용 예제.
  4. 2020.08.27 [Docker] 맥북에 우분투 올리기
  5. 2020.08.26 [Docker] Docker Container 내 Terraform 설치
  6. 2020.08.14 [Ansible] Elasticsearch + Docker Compose 구성 시 vm.max_map_count 이슈.
  7. 2020.08.14 [Ansible] apt lock 문제.
  8. 2020.07.31 [Terraform] S3 Backend 사용.
  9. 2020.04.08 [Docker] Docker Compose TZ 설정
  10. 2020.04.01 [Docker] Docker Compose 로 Ubuntu 올리기

[Docker] apk not found 또는 certificate verify failed:ssl 발생 시.

Cloud&Container/IaC 2022. 3. 24. 11:33

아래와 같은 에러 발생 시

Step 8/13 : RUN apk add tzdata
 ---> Running in 7d1593d1239f
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
140460674784072:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1914:
ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.14/main: Permission denied
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.14/main: No such file or directory
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
140460674784072:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1914:
ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.14/community: Permission denied
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.14/community: No such file or directory
ERROR: unable to select packages:
  tzdata (no such package):
    required by: world[tzdata]
The command '/bin/sh -c apk add tzdata' returned a non-zero code: 1

제가 사용했던 이미지는 OpenJDK 11 Alpine 입니다.

FROM adoptopenjdk/openjdk11:alpine

Timezone 설정을 위해서 

RUN apk add tzdata

를 Dockerfile 에 추가 했는데 에러가 발생을 했습니다.

 

찾아 보니 SSL 인증서 문제라고 해서 아래와 같이 수정 했습니다.

RUN sed 's/https/http/g' -i /etc/apk/repositories
RUN apk update
RUN apk add --no-cache bash
RUN apk add tzdata

나중에 또 기억 못할 것 같아서 기록 합니다.

:

[Docker] 로컬에 MySQL 설치 합니다.

Cloud&Container/IaC 2021. 7. 14. 19:39

요즘 잘 되어 있는 container 기반으로 구성 하면 되지 않겠습니까?

 

version: '3.7'

services:
  db:
    image: mysql
    container_name: local-mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: local
      MYSQL_USER: henry
      MYSQL_PASSWORD: henry
      MYSQL_DATABASE: henry
    volumes:
      - ./data:/var/lib/mysql
    ports:
      - 3306:3306

  adminer:
    image: adminer
    restart: always
    ports:
      - 8888:8888

$ docker-compose up -d

이제 client tool 을 이용해서 접속해 보시면 됩니다. :)

:

[Docker] ARG 와 ENV 사용 예제.

Cloud&Container/IaC 2021. 2. 1. 14:55

 

https://docs.docker.com/engine/reference/builder/#arg
https://docs.docker.com/engine/reference/builder/#env
https://docs.docker.com/compose/reference/build/
https://docs.docker.com/compose/environment-variables/

 

docker build 시 --builg-arg 를 사용 할 때가 있는데요.

arg 와 env 에 대한 차이를 이해 하고 사용 하면 좋을 것 같아 기록해 봅니다.

 

제가 하고 싶었던 건 아래와 같습니다.

 

파일 구조)

ㄴ .env
ㄴ docker-compose.yml
ㄴ Dockerfile

$ docker build --build-arg BASTION_IP=xxx.xxx.xxx.xxx --tag ecos-installer-web:0.0.1 .

 

여기서 --build-arg 를 사용하지 않고 build 를 하고 싶었습니다.
그래서 .env 를 구성 하고
docker-compose 를 이용해서 build 를 하는 방식으로 변경을 했습니다.

 

.env 에 BASTION_IP 추가)

BASTION_IP=xxx.xxx.xxx.xxx

 

Dockerfile 에 ARG 추가)

ARG BASTION_IP
...중략...
ENV configTerraformAwsBastionIp $BASTION_IP

 

docker-compose.yml 에 build 추가)

build:
  context: .
    args:
      - BASTION_IP=${BASTION_IP}

 

이렇게 변경 하고 docker build 를 하지 않고 docker-compose build 로 처리 했습니다.

$ docker-compose build or docker-compose up

 

:

[Docker] 맥북에 우분투 올리기

Cloud&Container/IaC 2020. 8. 27. 18:32

가끔 필요 할 때가 있습니다.

 

docker-compose.yml)

version: '3.7'
services:
  ubuntu-mac:
    image: ubuntu:18.04
    container_name: ubuntu-mac
    stdin_open: true
    tty: true
    command: [/bin/bash]

 

:

[Docker] Docker Container 내 Terraform 설치

Cloud&Container/IaC 2020. 8. 26. 08:26

아래와 같이 설치 하게 되면 0.11.x 버전이 설치가 됩니다.

Terraform 의 경우 syntax 가 버전에 따라 다른 부분이 있기 때문에 사용 하시는 버전에 맞추 설치 하시면 좋습니다.

 

RUN apk add terraform  

 

버전을 지정 해서 설치 하는 건 아래와 같이 하시면 됩니다.

RUN wget https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip
RUN unzip terraform_0.13.0_linux_amd64.zip && rm terraform_0.13.0_linux_amd64.zip
RUN mv terraform /usr/bin/terraform

위에서 0.13.0 에 대한 부분은 변수로 빼서 사용을 하셔도 됩니다.

 

ENV terraform-version 0.13.0
...중략...
RUN wget https://releases.hashicorp.com/terraform/${terraform-version}/terraform_${terraform-version}_linux_amd64.zip

참고문서)

https://docs.docker.com/engine/reference/builder/

 

:

[Ansible] Elasticsearch + Docker Compose 구성 시 vm.max_map_count 이슈.

Cloud&Container/IaC 2020. 8. 14. 14:36

vm.max_map_count 설정은 host 서버에 해주시면 문제는 해결 됩니다.

다만, 이를 수동으로 하면 아무 의미 없겠죠.

 

자동으로 구성 하기 위해서 terraform + ansible 사용 하는 건데 수동으로 할 거면 ....

 

처음에는 init.sh 라는 스크립트 안에서 처리 하도록 했습니다.

- name: Run a script with arguments
  script: init.sh

init.sh 에는 아래 코드가 들어가 있습니다.

sudo sysctl -w vm.max_map_count=262144

 

이렇게 했으면 당연히 elasticsearch 를 실행 시켰을 때 문제가 없을 줄 알았는데, 적용이 안되었는지 오류가 발생했습니다.

그래서 ansible 에 명령어를 추가 해서 문제를 해결했습니다.

- name: set vm.max_map_count
  shell: sudo sysctl -w vm.max_map_count=262144

 

$ ansible-playbook 해 보면 아래와 같은 warning 메시지가 나오는데요.

Consider using 'become', 'become_method', and 'become_user' rather than running sudo

 

- name: become parameters
  become: yes
  become_method: sudo
  become_user: ubuntu 

이렇게 넣어서 사용하라는 이야기 입니다.

 

[수정]

- name: set vm.max_map_count
  become: yes
  become_method: sudo
  shell: sysctl -w vm.max_map_count=262144
:

[Ansible] apt lock 문제.

Cloud&Container/IaC 2020. 8. 14. 14:27

ansible 을 이용해서 서버에 필요한 stack 들을 설치 해야 하는 경우 아래와 같은 에러가 발생 할 때가 있습니다.

 

[에러]

...중략...

E: Could not get lock /var/lib/dpkg/lock

...중략...

정리 하면 다른 프로세스가 이미 사용중이기 때문에 사용할 수 없다는 뭐 그런 이야기 입니다.

그렇다 보니 ansible 배포가 실패 하게 되는데요.

 

이를 해결 하기 위해서 wait_for 나 process check 나 retry 등 다양하게 해봤는데, 그나마 아래 코드가 제일 잘 동작해서 올려 봅니다.

 

[해결]

- name: Apt lock check
  apt: name=build-essential state=present
  register: apt_state
  until: apt_state is success
  delay: 30
  retries: 10

 

:

[Terraform] S3 Backend 사용.

Cloud&Container/IaC 2020. 7. 31. 14:21

공식 문서는 아래 참고 하세요.

https://www.terraform.io/docs/backends/types/s3.html

 

terraform {
  backend "s3" {
    bucket = "버킷이름"
    key    = "폴더/파일"
    region = "ap-northeast-2"
  }
}
  • s3 backend 를 사용하기 위해서 먼저 s3 bucket 을 생성 합니다.
  • key 부분은 미리 생성해 놓지 않아도 terraform 실행을 하시면 생성이 됩니다.
  • 만약 bucket 을 만들어 놓지 않고 실행을 하게 되면 아래와 같은 에러가 발생 합니다.
Error refreshing state: BucketRegionError: incorrect region, 
the bucket is not in 'ap-northeast-2' region at endpoint ''
	status code: 301, request id: , host id:
  • bucket 을 생성 하고  $ terraform init 을 해도 같은 에러가 계속 발생 합니다.
  • 이 경우 .terraform 폴더를 삭제 하고 다시 시도 하시면 정상적으로 동작 합니다.

Terraform 기본 명령어)

$ terraform init

$ terraform plan

$ terraform apply

$ terraform destroy

.aws 에 aws configure 를 통한 설정이 되어 있어야 합니다.

 

 

:

[Docker] Docker Compose TZ 설정

Cloud&Container/IaC 2020. 4. 8. 09:14

docker-compose tz 설정

 

Case 1)

volumes:
  - "/etc/localtime:/etc/localtime:ro"
  - "/etc/timezone:/etc/timezone:ro"


Case 2)

environment:
  - TZ=Asia/Seoul

 

:

[Docker] Docker Compose 로 Ubuntu 올리기

Cloud&Container/IaC 2020. 4. 1. 20:41

docker-compose.yml)

version: '3.7'
services:
  ubuntu-mac:
    image: ubuntu:18.04
    container_name: ubuntu-mac
    stdin_open: true
    tty: true
    command: [/bin/bash]

or

$ docker run --rm --name ubuntu-mac -ti ubuntu:18.04 /bin/bash

 

: