Docker embedded 개발 환경 설정

Embedded 리눅스를 개발 하면서, 우분투 버전업등의 이슈가 발생하면, 크로스 컴파일 환경에 문제가 생기곤 하였으며, 개발이 끝난이후 한참 시간이 흐른후 다시 빌드를 수행할 일이 있스면, 개발 환경 구축에 많은 시간이 들어 도커이미지로 만들어 두기로 하였다. 추후에도 계속 같은 방법을 쓸수 있도록 메뉴얼을 남겨 둔다.

1. SSH 접속용 이미지 생성

* 개발 환경은 Ubuntu 20.04 버전을 사용

$ vi DockerfileCode language: Shell Session (shell)
FROM ubuntu:20.04

# you should change user id and password
ENV userId="USERID"
ENV password="PASSWORD"

RUN apt update

# locale seeting
RUN apt install -y locales locales-all
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8

# for bash completion
RUN apt install bash-completion

# install SSH server
RUN apt install  openssh-server sudo -y
RUN service ssh start
CMD ["/usr/sbin/sshd","-D"]

EXPOSE 22

# add user account
RUN useradd -rm -d /home/$userId -s /bin/bash -G sudo -U -u 1000 $userId

# id:password
RUN  echo "$userId:$password" | chpasswd 

Code language: Dockerfile (dockerfile)

2. SSH 이미지 빌드

$ docker build -t ssh .Code language: Shell Session (shell)

3. Docker 컨테이너 생성 및 자동 실행을 위한 Docker compose yml 문서 작성

version: '2'

services:

  ssh:
    privileged: true
    image: ssh
    restart: always
    volumes:
      - develop:/home/USERID/develop
    stdin_open: true
    tty: true

volumes:
  develop:Code language: YAML (yaml)

4. Docker compose 실행

$ docker-compose up -dCode language: Shell Session (shell)