230117

su-mmer·2023년 1월 17일
0

아묻따 도커 공부

목록 보기
17/18

DOCKER OFFICIAL IMAGE 마크가 붙은 이미지만 사용할 것

# docker image를 hub에서 찾기
docker search <image_name>

# container 자세히보기
docker inspect [OPTIONS] NAME|ID [NAME|ID...]

# container 로그 확인
docker logs [OPTIONS] CONTAINER

# docker port 보이기
docker port CONTAINER [PRIVATE_PORT[/PROTO]]

# 컨테이너에서 실행중인 프로세스 출력
docker top CONTAINER [ps OPTIONS]

# 이미지에 태그 설정
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

각 컨테이너들은 컨테이너 ID를 가진다.
컨테이너 내부에 데이터 볼륨 및 저장소를 가진다.

# 도커 전체에 대한 정보 확인
docker info

3GB = 3000MB
3GiB = 1024*3MB

보안 구성 - 해킹 방지


#compose 설치
curl -SL https://github.com/docker/compose/releases/download/v2.14.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

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

docker-compose --version

# volume 경로 찾기 실습
docker run -d -p 5000:5000 --restart always --name registry registry:2

docker tag httpd:latest localhost:5000/httpd:latest

docker push localhost:5000/httpd:latest

volume 경로
/var/lib/docker/volumes/[Container_ID]/_data/docker/registry/v2/repositories/httpd


# 스트레스 테스트
cat > dockerfile

FROM debian
MAINTAINER kwjeon31 <kwjeon31@gmail.com>
run apt-get update; apt-get install -y stress
CMD ["bin/sh", "-c", "stress -c 2"]

docker build -t stress .

# memory-swap으로 100M를 쓰고 cpu는 2개 io 4, vmbyte 90m, timeout 1초
docker run -m 100m --memory-swap 100m stress:latest stress --cpu 2 --io 4 --vm-bytes 90m --timeout 1

# mysql 설치
docker run -d --name db -v /dbdata:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root mysql:latest

# 
echo "<h1> Docker Environment Test</h1>" > index.html

docker run -d --name web -v /home/guru/workspace/webdata:/usr/share/nginx/html:ro --rm -p 80:80 nginx:latest

docker cp /webdata/index.html  web:/usr/share/nginx/html

# 어디에 쓰는거?
docker run -it --name c1 busybox
# 라우팅 정보 확인
sudo apt install bridge-utils

brctl show
alias crm='docker rm -f $(docker ps -aq)'
# cat > df.sh

#!/bin/bash
mkdir -p /webdata
while true
do
   df -h / > /webdata/index.html
   sleep 10
done

---
# dockerfile

FROM ubuntu:18.04
ADD df.sh /bin/df.sh
RUN chmod +x /bin/df.sh
ENTRYPOINT ["/bin/df.sh"]
# docker network 생성

docker network create --driver bridge --subnet 192.168.100.0/24 --gateway 192.168.100.254 mynet

docker run -it --name c1 --net mynet --ip 192.168.100.100 --rm busybox


# 안 됨
docker run -d --name wordpressdb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wordpress mysql:5.7

docker run -p 80:80 -d --name wordpress -e WORDPRESS_DB_PASSWORD=root --link wordpressdb:mysql wordpress
# 안 됨

import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
    retries = 5
    while True:
        try:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)
@app.route('/')
def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)

---
# dockerfile

FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]

---
# docker-compose.yml

version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

0개의 댓글