1. 도커 이미지

1) 도커 이미지 검색

# docker images

2) 도커 단일 이미지 삭제

# docker image rm <image ID>

3) 도커 모든 이미지 삭제

# docker rmi $(docker images -q) -f

 

2. 도커 컨테이너 생성

1) 도커 컨테이너 생성 & 실행

# docker run <옵션> --name <컨테이너이름:test> <이미지 Repository>

2) 도커 컨테이너 생성만

# docker create <옵션> --name <컨테이너이름:test> <이미지 Repository>

 

3. 도커 컨테이너 접속

1) 도커 컨테이너 접속

# docker exec -it <컨테이너이름> /bin/bash

 

4. 도커 컨테이너 빠져나오기

컨테이너에서 빠져나오는 방법은 두가지가 있습니다.

1) 컨테이너를 종료하면서 빠져나오기

# exit 또는 ctrl+D

2) 컨테이너가 가동되는 상태를 유지하면서 접속만 종료하기

# ctrl + P 입력 후 Q 입력

 

5. 도커 컨테이너 실행/종료

1) 컨테이너 실행

# docker start <컨테이너이름>

2) 컨테이너 종료

# docker stop <컨테이너이름>

3) 모든 컨테이너 한번에 종료

# docker stop $(docker ps -qa)

4) 컨테이너 강제 종료 (SIGKILL 시그널 전달)

# docker kill [container]

5) 컨테이너 일시 중지

# docker pause [container]

6) 컨테이너 재개

# docker unpause [container]

 

6. 컨테이너 조회

1) 실행중인 컨테이너 리스트 출력

# docker ps

2) 전체 컨테이너 리스트 출력

# docker ps -a

3) 컨테이너 상세 정보 확인

# docker inspect [container]

 

7. 컨테이너 삭제

1) 개별 컨테이너 삭제

# docker rm <컨테이너이름>

2) 모든 컨테이너 한번에 삭제

# docker rm $(docker ps -qa)

3) 중지된 모든 컨테이너 삭제

# docker container prune

 

8. 컨테이너 로그 확인

1) 개별 컨테이너 로그 확인

# docker logs [컨테이너이름]

2) 마지막 로그부터 사용자가 지정한 라인까지 출력 (로그가 너무 많아 읽기 힘든 경우)

# docker logs --tail 10 [컨테이너이름]

3) 입력받은 유닉스 시간 이후의 로그 확인, -t 옵션으로 타임스탬프 표시 가능

# docker logs --since 1549150300 -t [컨테이너이름]

4) 실시간으로 생성되는 로그를 스트림으로 확인

# docker logs --tail 10 -f [컨테이너이름]

 

 

참고

https://narup.tistory.com/198

https://kimjingo.tistory.com/58

https://velog.io/@bbangi/Docker-%EC%83%9D%EC%84%B1-%EC%8B%A4%ED%96%89-%EC%A2%85%EB%A3%8C

https://sungwookkang.com/1299

준비 : EC2에 ssh로 접속한다.

 

Docker 설치

1. 패키지 업데이트 

sudo apt-get update

2. https관련 패키지 설치

sudo apt install apt-transport-https ca-certificates curl software-properties-common

3. docker repository 접근을 위한 gpg 키 설정

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4. docker repository 등록

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

5. 다시 패키지 업데이트

sudo apt update

6. 도커 설치

sudo apt-get install docker-ce docker-ce-cli containerd.io

7. 설치 확인

sudo docker --version

8. 도커로 hello-world 이미지 구동해봄

sudo docker run hello-world

9. 아래와 같은 메시지가 나오면 성공!

latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:926fac19d22aa2d60f1a276b66a20eb765fbeea2db5dbdaafeb456ad8ce81598
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/

 

Docker-compose 설치

docker-compose를 standalone 방식으로 설치하는 방법이다.

 

1. Compose standalone을 다운로드하고 설치

sudo curl -SL https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

2. 설치한 파일에 실행권한 추가

sudo chmod +x /usr/local/bin/docker-compose

3. 어느 위치에서든 docker-compose 명령을 사용하고 싶으면, 아래 심볼릭 링크 추가

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

4. docker-compose 버전 확인

sudo docker-compose -v

 

sudo 없이 docker 명령어 사용하기

1. 현재 사용자를 docker group에 포함

sudo usermod -aG docker ${USER}

사용자명이 ubuntu라면,

sudo usermod -aG docker ubuntu

2. 터미널 재시작 후 결과 확인(끝에 docker가 있는지 확인)

id -nG

 

참고

https://velog.io/@osk3856/Docker-Ubuntu-22.04-Docker-Installation

https://docs.docker.com/compose/install/standalone/

https://everydayyy.tistory.com/121

데이터베이스에 접속하려고 하는데, root 패스워드를 잊어버렸을 경우가 있다.

이런 경우 패스워드를 리셋하는 방법이다. (MariaDB 기준)

 

1. MariaDB서비스 중지

sudo systemctl stop mariadb

 

2. MariaDB를 --skip-grant-tables 옵션을 주어 실행함 (MariaDB service unit file을 수정하여 실행)

- 아래 명령을 실행하면, MariaDB service unit file 이 텍스트 에디터로 열림

sudo systemctl edit --full mariadb

- 해당 파일에서 ExecStart 부분을 찾아 아래와 같이 --skip-grant-tables 옵션을 추가함

ExecStart=/usr/sbin/mysqld --skip-grant-tables $MYSQLD_OPTS

- 파일을 저장하고 텍스트 에디터를 종료함

 

3. MariaDB를 수정된 unit file을 이용하여 실행함

sudo systemctl start mariadb

 

4. 이제 권한체크 없이 어드민 태스크를 실행할 수 있게 됨. 아래와 같이 패스워드 없이 DB 접속 가능해짐

mysql -u root

 

5. MariaDB 서버에 접속하면, 'mysql' 데이터베이스로 스위치함

use mysql;

 

6. root 패스워드를 새로운 패스워드로 설정함

update user set authentication_string=password('new_password') where user='root';

 

7. flush privileges를 하여 변경 사항을 반영시킴

flush privileges;

 

8. MariaDB 서버 접속을 종료함

exit;

 

9. MariaDB 서비스를 중지

sudo systemctl stop mariadb

 

10. MariaDB service unit file 에서, --skip-grant-tables 옵션을 삭제함

- 아래 명령을 실행하면, MariaDB service unit file 이 텍스트 에디터로 열림

sudo systemctl edit --full mariadb

- 해당 파일에서 ExecStart 부분을 찾아, 추가했던 --skip-grant-tables 옵션 삭제함

ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS

- 파일을 저장하고 텍스트 에디터를 종료함

 

11. MariaDB를 재실행함

sudo systemctl start mariadb

 

12. 이제 변경된 패스워드로 root 계정 접속이 가능하다.

mysql -u root -p

Qt의 메타-오브젝트 시스템(meta-object system)객체간 통신을 위한 시그널-슬롯 매커니즘과, 런타임 타입 정보, 동적 속성 시스템을 제공한다.

 

메타-오브젝트 시스템은 아래 세 가지를 기반으로 한다:

1. QObject 클래스 : 객체를 위한 기반 클래스를 제공하여 메타-오브젝트 시스템의 이점을 이용할 수 있게 한다.

2. Q_OBJECT 매크로 : 클래스의 private 섹션 안에 선언되며, 동적 속성과 시그널 슬롯 등의 메타-오브젝트 기능을 사용할 수 있게 한다.

3. Meta-Object Compiler(moc) : QObject의 자식 클래스들에게 필요한 메타-오브젝트 구현 코드를 제공한다.

 

moc 툴은 C++ 헤더, 소스 파일 읽어 Q_OBJECT 매크로가 포함된 클래스를 찾고,

이를 찾으면 각 클래스에 대해 메타-오브젝트 코드를 포함하는 또다른 C++ 소스 파일을 생성해낸다.

이렇게 생성된 소스파일은 인클루드, 컴파일되고 클래스 구현과 링크되어 사용된다.

 

예) 헤더파일에 Q_OBJECT 매크로가 있는 클래스가 있다면,

메타-오브젝트를 이용할 수 있는 코드들을 추가한 새로운 헤더 파일을 만들어내고,

이 헤더 파일을 include한 새로운 C++ 구현 파일이 생겨 빌드시에는 이를 컴파일하고 링크하여 사용한다.

 

 

참고

https://doc.qt.io/qt-6/metaobjects.html

https://coding-chobo.tistory.com/9

QTest로 유닛 테스트를 작성하고, CMake로 빌드파일 만들어 Visual Studio로 빌드하는데 아래와 같은 오류 메시지가 뜨는 경우가 있다.

 

오류메시지

error LNK2019: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)"

 

원인

main 함수가 없어 entry point가 제대로 설정되지 않았기 때문이다

 

해결책

테스트 케이스가 작성된 cpp 파일 하단에, 아래의 내용을 넣어주면 된다.

QTEST_MAIN(MyFirstTest)
#include "tst_myfirsttest.moc"

 

tst_myfirsttest.cpp 전체 소스

#include <QObject>
#include <QTest>
#include <qDebug>


class MyFirstTest : public QObject
{
    Q_OBJECT

private:
    bool myCondition()
    {
        return true;
    }

private slots:
    void initTestCase()
    {
        qDebug("Called before everything else.");
    }

    void myFirstTest()
    {
        QVERIFY(true);  // check that a condition is satisfied
        QCOMPARE(1, 1); // compare two values
    }

    void mySecondTest()
    {
        QVERIFY(myCondition());
        QVERIFY(1 != 2);
    }

    void cleanupTestCase()
    {
        qDebug("Called after myFirstTest and mySecondTest.");
    }
};

QTEST_MAIN(MyFirstTest)
#include "tst_myfirsttest.moc"

 

CMakeLists.txt

set(_components
    Core
    Test)

foreach(_component ${_components})
    find_package(Qt5${_component})
    list(APPEND QT_LIBRARIES ${Qt5${_component}_LIBRARIES})
    list(APPEND QT_INCLUDES ${Qt5${_component}_INCLUDE_DIRS})
    add_definitions(${Qt5${_component}_DEFINITIONS})
endforeach()

include_directories(${QT_INCLUDES})

find_program(QT_QMAKE_EXECUTABLE qmake)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

enable_testing(true)

add_executable(mytest tst_myfirsttest.cpp)
add_test(NAME mytest COMMAND mytest)
target_link_libraries(mytest PRIVATE ${QT_LIBRARIES})
qt_generate_moc(tst_myfirsttest.cpp tst_myfirsttest.moc TARGET mytest)

디스크 관련

디스크 사용량 보기

// 루트부터 뎁스별로 확인해가기
du -h --max-depth=1 
// 또는
du -h -d 1

디렉토리 크기로 정렬

// 내림차순
du -m -d 1 | sort -rn

// 오름차순
du -m -d 1 | sort -n

디스크 free 용량 보기

df -h

 

사용자 관련

사용자 추가

useradd [username]

 

사용자 추가하면서 그룹에도 추가

useradd -G [groupname] [username]

 

사용자 비밀번호 변경

passwd [username]

 

기존 사용자를 그룹에 추가

usermod -a -G [groupname] [username]

 

사용자 삭제

- 계정만 삭제

userdel [계정명]

- 계정 + 홈디렉토리 삭제

userdel -r [계정명]

 

디렉토리 관련

현재 디렉토리 위치(경로) 보기

pwd

 

디렉토리 생성

mkdir [생성할 디렉토리명]

예) mkdir test

 

디렉토리 삭제

- 빈 디렉토리 삭제

rmdir [삭제할 디렉토리명]

예) rmdir test

 

- 비어있지 않은 디렉토리와, 하위 파일들 모두 삭제

rmdir -r [삭제할 디렉토리명]

예) rmdir -r test

 

- 비어있지 않은 디렉토리와, 하위 파일(쓰기 금지된 파일 포함)들 모두 삭제

rmdir -rf [삭제할 디렉토리명]

예) rmdir -rf test

 

포트 관련

사용중인 포트 확인

netstat -ltup

ss -lntu

 

파일 관련

특정 파일에 실행권한 추가

// sudo chmod +x /usr/local/bin/[파일명]
sudo chmod +x /usr/local/bin/docker-compose

폴더를 나눠서, 하위 폴더에 있는 소스를 포함하여 exe 생성하는 cmake 예제입니다.

 

파일 구조

Root (folder)
+ CMakeLists.txt
+ main.cpp
+ src (folder)
   - CMakeLists.txt
   - test.h
   - test.cpp

 

Root 폴더의 CMakeLists.txt

# CMake 프로그램의 최소 버전
cmake_minimum_required(VERSION 3.11)

# 프로젝트 정보
project(
    myproject
    VERSION 0.1
    DESCRIPTION "myproject sample"
    LANGUAGES CXX)

# C++11 설정
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 확인할 디렉토리 추가 - 해당 디렉토리에 CMakeLists.txt를 읽고 실행함
# add_subdirectory(<소스 디렉토리명> [binary_dir] [EXCLUDE_FROM_ALL] [SYSTEM])
add_subdirectory(src)

# 빌드 최종 결과물로 생성할 실행파일 추가 - 실행파일명은 프로젝트이름인 myproejct를 사용함
# ADD_EXECUTABLE ( <실행_파일명> <소스_파일> <소스_파일> ... )
add_executable(${PROJECT_NAME} main.cpp)

# Target 링크시 포함할 라이브러리 목록 지정
# TARGET_LINK_LIBRARIES ( <Target_이름> <라이브러리> <라이브러리> ... )
target_link_libraries(${PROJECT_NAME} test)

 

Root 폴더 하위에 있는 src 폴더의 CMakeLists.txt

# 빌드 최종 결과물로 생성할 라이브러리 추가 - 정적 라이브러리 test 를 만듦
# ADD_LIBRARY ( <라이브러리_이름> [STATIC|SHARED|MODULE] <소스_파일> <소스_파일> ... )
add_library(test STATIC test.h test.cpp)

 

참고

https://www.tuwlab.com/27260

https://modoocode.com/332

Electron이란

Electron(이전의 Atom Shell)은 OpenJS Foundation에서 개발 및 유지 관리하는 무료 오픈 소스 소프트웨어 프레임워크입니다. 이 프레임워크는 Chromium 브라우저 엔진 버전을 사용하여 렌더링되는 웹 기술(주로 HTML, CSS 및 JavaScript, 프런트엔드 프레임워크 및 웹 어셈블리와 같은 다른 기술도 가능함)을 사용하여 데스크톱 애플리케이션을 생성하도록 설계되었으며 백엔드는 Node.js 런타임 환경을 사용합니다. 또한 다양한 API를 사용하여 Node.js 서비스 및 프로세스 간 통신 모듈과의 기본 통합과 같은 기능을 활성화합니다.

Electron은 원래 Atom용으로 제작되었으며 Atom, GitHub Desktop, Light Table, Visual Studio Code, WordPress Desktop 및 Eclipse Theia를 포함한 여러 오픈 소스 프로젝트의 기본 GUI 프레임워크입니다.

 

참고

https://www.electronjs.org/

https://en.wikipedia.org/wiki/Electron_(software_framework)

+ Recent posts