ubuntu 서버 만들기
가상 머신 만들기
ssh -i ~/.ssh/id_rsa.pem winkey@20.200.217.203
sudo apt-get update
sudo apt-get upgrade
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
$ sudo docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
7c457f213c76: Pull complete
Digest: sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 f9a80a55f492 7 months ago 63.2MB
hello-world latest d2c94e258dcb 8 months ago 13.3kB
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
31c0991209b4 hello-world "/hello" 19 minutes ago Exited (0) 19 minutes ago zealous_cohen
$ sudo docker run -it --name demo1 ubuntu:18.04 /bin/bash
root@06d4ae567214:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@06d4ae567214:/etc# exit
exit
winkey@labuser93ubuntu:~$
$ sudo docker run -it -d --name demo2 ubuntu:18.04
2e5aeafde515f253ae5653528951caededd5733d2874104afe49a4e2ecd7514f
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e5aeafde515 ubuntu:18.04 "/bin/bash" 13 seconds ago Up 12 seconds
demo2
$ sudo docker exec -it demo2 /bin/bash
root@2e5aeafde515:/#
$ sudo docker run --name demo5 -d busybox sh -c "while true;do
$(echo date);sleep 1; done"
a3083ce2f910269d1e2fdcf718c6cf6e055fb9485c9b22d05240918b1894c799
$ sudo docker logs demo5
Thu Jan 11 03:27:26 UTC 2024
Thu Jan 11 03:27:28 UTC 2024
Thu Jan 11 03:27:29 UTC 2024
Thu Jan 11 03:27:30 UTC 2024
Thu Jan 11 03:27:31 UTC 2024
Thu Jan 11 03:27:32 UTC 2024
$ sudo docker logs demo5 -f
Thu Jan 11 03:27:26 UTC 2024
Thu Jan 11 03:27:28 UTC 2024
Thu Jan 11 03:27:29 UTC 2024
Thu Jan 11 03:27:30 UTC 2024
Thu Jan 11 03:27:31 UTC 2024
Thu Jan 11 03:27:32 UTC 2024
... 계속 반복
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3083ce2f910 busybox "sh -c 'while true;d…" About an hour ago Up About an hour demo5
2e5aeafde515 ubuntu:18.04 "/bin/bash" About an hour ago Up About an hour demo2
$ sudo docker stop demo5
demo5
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e5aeafde515 ubuntu:18.04 "/bin/bash" About an hour ago Up About an hour demo2
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3083ce2f910 busybox "sh -c 'while true;d…" About an hour ago Exited (137) 2 minutes ago demo5
71c788454ee6 busybox "sh -c 'while true;d…" About an hour ago Exited (2) About an hour ago demo3
2e5aeafde515 ubuntu:18.04 "/bin/bash" About an hour ago Exited (0) About a minute ago demo2
06d4ae567214 ubuntu:18.04 "/bin/bash" 2 hours ago Exited (0) 2 hours ago demo1
31c0991209b4 hello-world "/hello" 2 hours ago Exited (0) 2 hours ago zealous_cohen
$ sudo docker rm demo1
demo1
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3083ce2f910 busybox "sh -c 'while true;d…" About an hour ago Exited (137) 4 minutes ago demo5
71c788454ee6 busybox "sh -c 'while true;d…" About an hour ago Exited (2) About an hour ago demo3
2e5aeafde515 ubuntu:18.04 "/bin/bash" 2 hours ago Exited (0) 3 minutes ago demo2
31c0991209b4 hello-world "/hello" 2 hours ago Exited (0) 2 hours ago zealous_cohen
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 9211bbaa0dbd 3 weeks ago 4.26MB
ubuntu 18.04 f9a80a55f492 7 months ago 63.2MB
hello-world latest d2c94e258dcb 8 months ago 13.3kB
$ sudo docker rmi busybox
Untagged: busybox:latest
Untagged: busybox@sha256:ba76950ac9eaa407512c9d859cea48114eeff8a6f12ebaa5d32ce79d4a017dd8
Deleted: sha256:9211bbaa0dbd68fed073065eb9f0a6ed00a75090a9235eca2554c62d1e75c58f
Deleted: sha256:82ae998286b2bba64ce571578647adcabef93d53867748d6046cc844ff193a83
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 f9a80a55f492 7 months ago 63.2MB
hello-world latest d2c94e258dcb 8 months ago 13.3kB
$ sudo docker rmi ubuntu:18.04
Untagged: ubuntu:18.04
Untagged: ubuntu@sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98
Deleted: sha256:f9a80a55f492e823bf5d51f1bd5f87ea3eed1cb31788686aa99a2fb61a27af6a
Deleted: sha256:548a79621a426b4eb077c926eabac5a8620c454fb230640253e1b44dc7dd7562
touch Dockerfile
FROM <image>[:<tag>] [AS <name>]
# 예시
FROM ubuntu
FROM ubuntu:18.04
FROM ngix:latest AS ngx
<src>
의 파일 혹은 디렉토리를 <dest>
경로에 복사하는 명령어입니다.COPY <src>... <dest>
# 예시
COPY a.txt /some-directory/b.txt
COPY my-directory /some-directory-2
RUN <command>
RUN ["excutable-command", 'parameter1', 'parameter2']
# 예시
RUN pip install torch
RUN pip install -r requirements.txt
CMD <command>
CMD ["executable-command", "parameter1", "parameter2"]
CMD ["parameter1", "parameter2"] # ENTRYPOINT 와 함께 사용될 때
# 예시
CMD python main.py
CMD
WORKDIR /path/to/workdir
# 예시
WORKDIR /home/demo
ENV <key> <value>
ENV <key>=<value>
# 예시
# default 언어 설정
RUN locale-gen ko_KR.UTF-8
ENV LANG ko_KR.UTF-8
ENV LANGUAGE ko_KR.UTF-8
ENV LC_ALL ko_KR.UTF-8
EXPOSE <port>
EXPOSE <port>/<protocol>
# 예시
EXPOSE 8080
vi Dockerfile
FROM ubuntu:18.04
RUN apt-get update
CMD ["echo", "Hello Docker"]
sudo docker build -t my-image:v1.0.0 .
sudo docker run my-image:v1.0.0
sudo docker run -d -p 5000:5000 --name registry registry
$ sudo docker tag my-image:v1.0.0 localhost:5000/my-image:v1.0.0
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-image v1.0.0 bf450d7aa616 23 minutes ago 109MB
localhost:5000/my-image v1.0.0 bf450d7aa616 23 minutes ago 109MB
registry latest 909c3ff012b7 5 weeks ago 25.4MB
$ sudo docker push localhost:5000/my-image:v1.0.0
The push refers to repository [localhost:5000/my-image]
b5858e8710d9: Pushed
548a79621a42: Pushed
v1.0.0: digest: sha256:16982bd2cd1153fe0a9b875396f3881862b6a6c77e6f788b5b5d7575b345dff8 size: 741
$ sudo docker login
Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/
Username: newnyup319
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
sudo docker tag my-image:v1.0.0 newnyup319/my-image:v1.0.0
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-image v1.0.0 bf450d7aa616 43 minutes ago 109MB
newnyup319/my-image v1.0.0 bf450d7aa616 43 minutes ago 109MB
localhost:5000/my-image v1.0.0 bf450d7aa616 43 minutes ago 109MB
registry latest 909c3ff012b7 5 weeks ago 25.4MB
$ sudo docker push newnyup319/my-image:v1.0.0
The push refers to repository [docker.io/newnyup319/my-image]
b5858e8710d9: Pushed
548a79621a42: Mounted from library/ubuntu
v1.0.0: digest: sha256:9e9bddec89c0b29a3fc8ac560f52cc3aa47ffedb7d03ad550c4215a555fec1a7 size: 741
image_url = 'https://cdn.huffingtonpost.kr/news/photo/201602/22260_43420.jpeg'
from PIL import Image
from io import BytesIO
import requests
Image.open(BytesIO(requests.get(image_url).content))
key = '[key를 입력하세요]'
endpoint = 'https://labuser93computervision.cognitiveservices.azure.com/'
endpoint = endpoint + 'vision/v2.0/'
analyze_endpoint = endpoint + 'analyze' # 분석
detect_endpoint = endpoint + 'detect' # 객체 탐지
ocr_endpoint = endpoint + 'ocr' # 글자 인식
headers = {'Ocp-Apim-Subscription-Key': key}
params = {'visualFeatures': 'Categories,Description,Color'}
data = {'url': image_url}
response = requests.post(analyze_endpoint,
headers=headers,
params=params,
json=data)
result = response.json()
result['description']
{'tags': ['sitting',
'cat',
'brown',
'indoor',
'dog',
'looking',
'animal',
'staring',
'camera',
'standing',
'tan',
'front',
'table',
'laying',
'close',
'orange',
'bed'],
'captions': [{'text': 'a close up of a dog and a cat looking at the camera',
'confidence': 0.8600456236335963}]}
# Object Detection
response = requests.post(detect_endpoint,
headers=headers,
json=data)
result = response.json()
result
{'objects': [{'rectangle': {'x': 195, 'y': 53, 'w': 360, 'h': 493},
'object': 'dog',
'confidence': 0.92,
'parent': {'object': 'mammal',
'confidence': 0.934,
'parent': {'object': 'animal', 'confidence': 0.935}}},
{'rectangle': {'x': 0, 'y': 235, 'w': 260, 'h': 317},
'object': 'cat',
'confidence': 0.869,
'parent': {'object': 'mammal',
'confidence': 0.88,
'parent': {'object': 'animal', 'confidence': 0.881}}}],
'requestId': '179b4ac2-6cd9-4b8e-8afb-b74e7092fa6a',
'metadata': {'height': 552, 'width': 570, 'format': 'Jpeg'}}