반응형
그니_
삽질탐방기
그니_
  • 분류 전체보기 (24)
    • 개발 (15)
    • ETC (1)
    • 트러블슈팅 & 삽질기록 (7)
    • 성능개선 (1)

인기 글

최근 글

최근 댓글

태그

  • chatgpt 확장 프로그램
  • spring docker
  • java
  • GPT 플러그인
  • springboot
  • chatgpt 확장 추천
  • Database
  • index
  • chatgpt 정리
  • chatgpt 채팅 삭제
  • Spring
  • 네트워크
  • spring docker compose
  • chatgpt 히스토리 삭제
  • timeunit
  • 마이크로소프트 ai tour
  • easyrandom
  • spring log
  • chatgpt 기록 삭제
  • db
hELLO · Designed By 정상우.
그니_

삽질탐방기

개발

SSH into docker container

2022. 7. 11. 03:23
반응형

여러 노드들에 대해 접근해 명령어를 통해 script나 정보들을 조회해야 될 일이 생겼다. 테스트 베드를 구축하기 위해 VM을 통해 서버를 구

 

축할까 하다 Docker로 하게 됐다.

 

standard한 ubuntu 이미지 하나만 있으면 되서 순조롭게 잘 되나 싶었는데 ssh 22번 포트 접근이 안되더라...

 

결국은 포트 바인딩 문제였는데 나중을 위해 정리를 해둘려고 한다.

 

1. docker 설치유무

설치확인
$ docker --version
$ Docker version 20.10.7, build f0df350

없으면
$ brew install docker

2. 다운로드 가능한 이미지 검색

$ docker search ubuntu

NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                           Ubuntu is a Debian-based Linux operating sys…   14566     [OK]       
websphere-liberty                WebSphere Liberty multi-architecture images …   286       [OK]       
ubuntu-upstart                   DEPRECATED, as is Upstart (find other proces…   112       [OK]       
neurodebian                      NeuroDebian provides neuroscience research s…   91        [OK]       
open-liberty                     Open Liberty multi-architecture images based…   53        [OK]       
ubuntu/nginx                     Nginx, a high-performance reverse proxy & we…   52                   
ubuntu-debootstrap               DEPRECATED; use "ubuntu" instead                46        [OK]       
ubuntu/apache2                   Apache, a secure & extensible open-source HT…   36                   
ubuntu/mysql                     MySQL open source fast, stable, multi-thread…   34                   
kasmweb/ubuntu-bionic-desktop    Ubuntu productivity desktop for Kasm Workspa…   29                   
ubuntu/prometheus                Prometheus is a systems and service monitori…   27                   
ubuntu/squid                     Squid is a caching proxy for the Web. Long-t…   25                   
ubuntu/bind9                     BIND 9 is a very flexible, full-featured DNS…   22                   
ubuntu/postgres                  PostgreSQL is an open source object-relation…   17                   
ubuntu/redis                     Redis, an open source key-value store. Long-…   10                   
ubuntu/grafana                   Grafana, a feature rich metrics dashboard & …   6                    
ubuntu/prometheus-alertmanager   Alertmanager handles client alerts from Prom…   6                    
ubuntu/kafka                     Apache Kafka, a distributed event streaming …   6                    
ubuntu/memcached                 Memcached, in-memory keyvalue store for smal…   5                    
ubuntu/telegraf                  Telegraf collects, processes, aggregates & w…   4                    
ubuntu/zookeeper                 ZooKeeper maintains configuration informatio…   4                    
ubuntu/cortex                    Cortex provides storage for Prometheus. Long…   3                    
ubuntu/cassandra                 Cassandra, an open source NoSQL distributed …   2                    
bitnami/ubuntu-base-buildpack    Ubuntu base compilation image                   2                    [OK]
ubuntu/loki                      Grafana Loki, a log aggregation system like …   0

 

3. ubuntu 이미지 다운로드

$ docker pull ubuntu

 

4. 이미지 목록 확인

$ docker images -a   

REPOSITORY                           TAG        IMAGE ID       CREATED         SIZE
ubuntu                               latest     27941809078c   4 weeks ago     77.8MB
some-temp-folder_review              latest     3b13c56d6616   10 months ago   667MB
some-temp-folder_recommendation      latest     2be47ed976d5   10 months ago   667MB
some-temp-folder_product-composite   latest     79cbaa37bbde   10 months ago   667MB
some-temp-folder_product             latest     5975341c2310   10 months ago   667MB
k8s.gcr.io/kube-apiserver            v1.21.2    106ff58d4308   12 months ago   126MB
k8s.gcr.io/kube-proxy                v1.21.2    a6ebd1c1ad98   12 months ago   131MB
k8s.gcr.io/kube-controller-manager   v1.21.2    ae24db9aa2cc   12 months ago   120MB
k8s.gcr.io/kube-scheduler            v1.21.2    f917b8c8f55b   12 months ago   50.6MB
docker/desktop-vpnkit-controller     v2.0       8c2c38aa676e   14 months ago   21MB
....

 

5. 컨테이너 실행

추가적인 옵션들은 $ docker run --help을 통해 옵션을 찾아 argument를 전달해주면 됨!  

$ docker run (<옵션>) <이미지 식별자> (<명령어>) (<인자>)

* -p 옵션을 통해 port-fowarding (-it는 exec 명령 위함.)
$ docker run -it -p {local-port}:{conatiner-port} --name ubuntu ubuntu /bin/bash

example
$ docker run -it -p 5222:22 --name ubuntu ubuntu /bin/bash
root@0f50b0066cca:/#

 

6. 편집기 및 openssh 설치

$ apt-get update (패키지 업데이트)
$ apt-get install vim openssh-server (conf 편집 및 ssh server 접근을 위해 설치)

 

7.  conf 수정

중간쯤 있으나 찾기 힘드면 vim 명령어로 찾기 :?PermitRootLogin

$ vim /etc/ssh/sshd_config

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
...

#LoginGraceTime 2m
#PermitRootLogin prohibit-password -> PermitRootLogin YES (주석 지우고 YES로 변경)
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

 

8. ssh start || restart

수정된 conf 적용을 위함.

$ service ssh status (상태확인, 설치만 해서 구동전.)
 * sshd is not running
 
$ service ssh start (service 구동)
 * Restarting OpenBSD Secure Shell server sshd

9. 패스워드 설정

ssh로 접속시 username, password 필요하기에 설정

$ passwd
New password: 
Retype new password:

10. 접속 확인

-p option의 argument는 위 5번에서 fowording한 port  

$ ssh root@127.0.0.1 -p 5222

root@127.0.0.1's password: 
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.10.25-linuxkit x86_64)

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

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@0f50b0066cca:~#

 

반응형

'개발' 카테고리의 다른 글

flyway를 이용한 db migration  (0) 2022.10.05
[네트워크]패킷  (0) 2022.07.31
VLAN  (0) 2022.07.07
WebRTC  (0) 2022.07.06
참고 사이트 정리  (0) 2022.07.06
    '개발' 카테고리의 다른 글
    • flyway를 이용한 db migration
    • [네트워크]패킷
    • VLAN
    • WebRTC
    그니_
    그니_
    머리속에서만 존재하는 내용을 글로 정리

    티스토리툴바