클라우드 + DevOps/Docker

Docker 컨테이너 구축 실습으로 docker 명령어 알아보기 (3): Portainer, 리눅스 알파인

gamjadori 2024. 2. 8. 11:24
728x90

<Portainer 컨테이너 구축>

1. 컨테이너 이미지 불러오기

ubuntu@host1:~/works$ docker pull portainer/portainer-ce
Using default tag: latest
latest: Pulling from portainer/portainer-ce
379538b6d68e: Pull complete 
4ea3e2c3a39b: Pull complete 
5171176db7f2: Pull complete 
52e9438966a5: Pull complete 
43d4775415ac: Pull complete 
c1cad9f5200f: Pull complete 
22eab514564f: Pull complete 
962b9fa821a2: Pull complete 
c153fefda5ce: Pull complete 
bed990c4615b: Pull complete 
4f4fb700ef54: Pull complete 
Digest: sha256:908d04d20e86f07a50b0f1a029a111b89aa3089b7fc7fdf68ec1c71b025f36cd
Status: Downloaded newer image for portainer/portainer-ce:latest
docker.io/portainer/portainer-ce:latest

 

2. 볼륨 생성 옵션을 이용해 컨테이너 생성

  • 볼륨: Docker 컨테이너의 생명 주기와 관계없이 데이터를 영속적으로 저장
ubuntu@host1:~/works$ docker volume create portainer_data
portainer_data
ubuntu@host1:~/works$ docker volume ls
DRIVER    VOLUME NAME
local     3c6934ae8b00c0075ee164b4adf4db3efd685465b23936fbe61323800a1d100a
local     7218ff99f0ef01950ab25d481f4e099e049adf6c750e5c76cd9bf9b797ed465c
local     portainer_data

 

3. 컨테이너 접속

  • -v: 볼륨 옵션
  • —restart: 컨테이너가 죽어도 다시 재구동해
ubuntu@host1:~/works$ docker container run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data --restart=always portainer/portainer-ce
d8186f16e4f6a4673208ed2ea7eb542ad70bfb3bbbdd75fac9cc5ef31081f77a

 

<컨테이너 확인>

  1. docker container ps: 상태 확인
ubuntu@host1:~/works$ docker container ps
CONTAINER ID   IMAGE                          COMMAND                   CREATED             STATUS             PORTS                                                           NAMES
d8186f16e4f6   portainer/portainer-ce         "/portainer"              29 seconds ago      Up 28 seconds      8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   infallible_mclaren
68858f6f8205   mariadb:10.2                   "docker-entrypoint.s…"   About an hour ago   Up About an hour   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp                       mariadb
0b9369296812   myweb:1.0                      "/docker-entrypoint.…"   2 hours ago         Up 2 hours         0.0.0.0:8002->80/tcp, :::8002->80/tcp                           mywebserver2
68ab46dfd9ce   nginx:1.25.3-alpine3.18-slim   "/docker-entrypoint.…"   3 hours ago         Up 3 hours         0.0.0.0:8001->80/tcp, :::8001->80/tcp                           my-webserver1

 

2. 브라우저에서 접속 확인

 

< 리눅스 알파인 컨테이너 구축>

<컨테이너 생성 및 접속>

  • —rm: 컨테이너가 종료되면 자동 삭제
ubuntu@host1:~/Labs/ch02$ docker container run -it --rm --name=linuxalpine alpine
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
661ff4d9561e: Pull complete
Digest: sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48
Status: Downloaded newer image for alpine:latest

 

<컨테이너 생성 (가동은 안되고 생성만 됨)>

  • docker container create: 생성만 함
ubuntu@host1:~/Labs/ch02$ docker container create -it --name myalpine alpine
ubuntu@host1:~/Labs/ch02$ docker start myalpine
>> 하고 docker ps -a 하면 UP 상태 확인 가능 

>> 컨테이너로 들어가는 방법: docker container attach

ubuntu@host1:~/Labs/ch02$ docker container attach myalpine
/ # >> 접속 가능