์ด๋ฒ์๋ Python Programming ํ๊ฒฝ์ Container๋ก ์ ๊ณตํด ๋ณด๊ธฐ ์ํ ์ค์ต์ ํ๋ฒ ํด๋ณด๊ฒ ์ต๋๋ค.
Docker ์ปจํ ์ด๋์ Python ์ด๋ฏธ์ง ์ค์น ๋ฐ ์คํ
# ์ํ ์์ค ์ฝ๋ ์์ฑ(๋ก๋ ํ๋ก๊ทธ๋จ)
$ vi py_lotto.py
from random import shuffle
from time import sleep
gamenum = input('๋ก๋ ๊ฒ์ ํ์๋ฅผ ์
๋ ฅํ์ธ์: ')
for i in range(int(gamenum)):
balls = [x+1 for x in range(45)]
ret = []
for j in range(6):
shuffle(balls) # balls๋ฅผ ๋ฌด์์๋ก ์๊ณ ,
number = balls.pop() # balls์ ์ ์ผ ๋ง์ง๋ง ์ซ์๋ฅผ ์ถ์ถํ๊ณ , ์ ๊ฑฐ
ret.append(number) # ์ถ์ถ๋ ์ซ์๋ฅผ ret์ ์ถ๊ฐ
ret.sort()
print('๋ก๋๋ฒํธ[%d]: ' % (i+1), end='')
print(ret)
sleep(1)
- Python Container ์คํ ํ py_lotto.py ์ํ ์ฝ๋๋ฅผ ๋ณต์ฌํฉ๋๋ค.
- ๋จผ์ , docker run ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ Python ์ปจํ ์ด๋๋ฅผ ์ค์นํ๊ณ ์คํํฉ๋๋ค. ์๋ ๋ช ๋ น์ด๋ python:latest ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ์ฌ python_test๋ผ๋ ์ด๋ฆ์ ์ปจํ ์ด๋๋ฅผ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํํฉ๋๋ค. -p 8900:8900 ์ต์ ์ ํธ์คํธ์ 8900๋ฒ ํฌํธ๋ฅผ ์ปจํ ์ด๋์ 8900๋ฒ ํฌํธ์ ๋งคํํฉ๋๋ค.
toby@tobykakao:~$ docker run -it -d --name=python_test -p 8900:8900 python
Unable to find image 'python:latest' locally
latest: Pulling from library/python
c1e0ef7b956a: Already exists
95b894d63c77: Pull complete
cb5594266b1b: Pull complete
59d4884f8528: Pull complete
d2dab3c2913c: Pull complete
19c44926628f: Pull complete
8c7b7fcf5c89: Pull complete
Digest: sha256:a31cbb4db18c6f09e3300fa85b77f6d56702501fcb9bdb8792ec702a39ba6200
Status: Downloaded newer image for python:latest
8d3a7836310293de69e69500c137324c5f71a4c75bb3733fe7d19044628016ad
- ํ์ด์ฌ ์ปจํ ์ด๋๋ฅผ ํ์ธํฉ๋๋ค.
- ์ปจํ ์ด๋๊ฐ ์คํ๋ ํ, Python ํ์ผ์ ์ปจํ ์ด๋ ๋ด๋ถ๋ก ๋ณต์ฌํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, py_lotte.py๋ผ๋ ํ์ผ์ python_test ์ปจํ ์ด๋์ ๋ณต์ฌํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- ๊ทธ๋ค์, docker exec ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ python_test ์ปจํ ์ด๋์ ์ ์ํ๊ณ Python ์ธํฐํ๋ฆฌํฐ๋ฅผ ์คํํ๊ฑฐ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ ์ ์์ต๋๋ค.
toby@tobykakao:~$ docker cp py_lotte.py python_test:/
Successfully copied 2.56kB to python_test:/
toby@tobykakao:~$ docker exec -it python_test bash
root@8d3a78363102:/# python
Python 3.13.0 (main, Oct 19 2024, 18:03:27) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
- python ๊ด๋ จ ๋๊ตฌ๋ฅผ ํ์ธํฉ๋๋ค.
root@8d3a78363102:/# pip list
Package Version
------- -------
pip 24.2
- ํ์ด์ฌ ์ปจํ ์ด๋์ ์ค์น๋ ํ์ผ์ ๋ชจ๋์ ํ์ธํฉ๋๋ค.
root@8d3a78363102:/# python -c 'help("modules")'
Please wait a moment while I gather a list of all available modules...
__future__ _stat faulthandler re
__hello__ _statistics fcntl readline
__phello__ _string filecmp reprlib
_abc _strptime fileinput resource
_aix_support _struct fnmatch rlcompleter
_android_support _suggestions fractions runpy
_ast _symtable ftplib sched
_asyncio _sysconfig functools secrets
_bisect _sysconfigdata__linux_aarch64-linux-gnu gc select
_blake2 _testbuffer genericpath selectors
_bz2 _testcapi getopt shelve
_codecs _testclinic getpass shlex
_codecs_cn _testclinic_limited gettext shutil
_codecs_hk _testexternalinspection glob signal
_codecs_iso2022 _testimportmultiple graphlib site
_codecs_jp _testinternalcapi grp smtplib
_codecs_kr _testlimitedcapi gzip socket
_codecs_tw _testmultiphase hashlib socketserver
_collections _testsinglephase heapq sqlite3
_collections_abc _thread hmac sre_compile
_colorize _threading_local html sre_constants
_compat_pickle _tkinter http sre_parse
_compression _tokenize idlelib ssl
_contextvars _tracemalloc imaplib stat
_csv _typing importlib statistics
_ctypes _uuid inspect string
_ctypes_test _warnings io stringprep
_curses _weakref ipaddress struct
_curses_panel _weakrefset itertools subprocess
_datetime _xxtestfuzz json symtable
_dbm _zoneinfo keyword sys
_decimal abc linecache sysconfig
_elementtree antigravity locale syslog
_functools argparse logging tabnanny
_gdbm array lzma tarfile
_hashlib ast mailbox tempfile
_heapq asyncio marshal termios
_imp atexit math textwrap
_interpchannels base64 mimetypes this
_interpqueues bdb mmap threading
_interpreters binascii modulefinder time
_io bisect multiprocessing timeit
_ios_support builtins netrc tkinter
_json bz2 ntpath token
_locale cProfile nturl2path tokenize
_lsprof calendar numbers tomllib
_lzma cmath opcode trace
_markupbase cmd operator traceback
_md5 code optparse tracemalloc
_multibytecodec codecs os tty
_multiprocessing codeop pathlib turtle
_opcode collections pdb turtledemo
_opcode_metadata colorsys pickle types
_operator compileall pickletools typing
_osx_support concurrent pip unicodedata
_pickle configparser pkgutil unittest
_posixshmem contextlib platform urllib
_posixsubprocess contextvars plistlib uuid
_py_abc copy poplib venv
_pydatetime copyreg posix warnings
_pydecimal csv posixpath wave
_pyio ctypes pprint weakref
_pylong curses profile webbrowser
_pyrepl dataclasses pstats wsgiref
_queue datetime pty xml
_random dbm pwd xmlrpc
_sha1 decimal py_compile xxlimited
_sha2 difflib py_lotte xxlimited_35
_sha3 dis pyclbr xxsubtype
_signal doctest pydoc zipapp
_sitebuiltins email pydoc_data zipfile
_socket encodings pyexpat zipimport
_sqlite3 ensurepip queue zlib
_sre enum quopri zoneinfo
_ssl errno random
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".
root@8d3a78363102:/# exit
exit
- ์ธ๋ถ์์ ํ์ด์ฌ ์ปจํ ์ด๋ ์ฝ๋๋ฅผ ์คํํด๋ณด๊ฒ ์ต๋๋ค.
toby@tobykakao:~$ docker exec -it python_test python /py_lotte.py
\ub85c\ub610 \uac8c\uc784 \ud69f\uc218\ub97c \uc785\ub825\ud558\uc138\uc694: 5
\ub85c\ub610\ubc88\ud638[1]: [5, 15, 26, 35, 37, 45]
\ub85c\ub610\ubc88\ud638[2]: [2, 4, 5, 6, 16, 30]
\ub85c\ub610\ubc88\ud638[3]: [7, 14, 23, 24, 30, 44]
\ub85c\ub610\ubc88\ud638[4]: [9, 12, 15, 25, 32, 45]
\ub85c\ub610\ubc88\ud638[5]: [8, 15, 19, 40, 43, 44]
Container ๋ด๋ถ์ ์์ค์ฝ๋, ๊ตฌ์ฑ ์ ๋ณด (conf)๋ฑ์ ๋ณ๊ฒฝํ๋ ๊ฒฝ์ฐ docker cp๊ฐ ์ ์ฉํฉ๋๋ค. ์๋ฅผ ๋ค์ด์, ngnix์ ๊ตฌ์ฑํ์ผ์ธ ngnix.conf๋ฅผ ์์ ํด์ผ ํ๋ค๋ฉด ๊ตณ์ด ์ปจ๋ฐ์ด๋์ ํธ์ง๊ธฐ๋ฅผ ์ค์นํ๋ ์๊ณ ๋ฅผ ๋ค์ด๊ฑฐ๋ ๊ฒฝ๋์ ์ปจํ ์ด๋๋ฅผ ๋ฌด๊ฒ๊ฒ ํ ํ์๊ฐ ์์ต๋๋ค.
docker run ๋ช ๋ น์ด๋ก Python ์ปจํ ์ด๋๋ฅผ ์ค์นํ๊ณ ์คํ.
docker cp ๋ก Python ํ์ผ์ ์ปจํ ์ด๋๋ก ๋ณต์ฌ.
docker exec ๋ก ์ปจํ ์ด๋ ๋ด์์ Python ์คํฌ๋ฆฝํธ ์คํ.
Docker๋ฅผ ํ์ฉํ Nginx ์ปจํ ์ด๋ ์ค์ ๋ฐ ๊ตฌ์ฑ ํ์ผ ๊ด๋ฆฌ
Nginx Docker ์ปจํ ์ด๋๋ฅผ ์์ฑํ๊ณ , Nginx ์ค์ ํ์ผ์ ํธ์คํธ๋ก ๋ณต์ฌํ ๋ค ์์ ํ์ฌ ๋ค์ ์ปจํ ์ด๋๋ก ๋ณต์ฌํ๊ณ ์ฌ์์ํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํด ๋ณด๊ฒ ์ต๋๋ค.
๋จผ์ , docker run ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ Nginx ์ปจํ ์ด๋๋ฅผ ์์ฑํฉ๋๋ค. -p 8010:80 ์ต์ ์ ํธ์คํธ์ 8010๋ฒ ํฌํธ๋ฅผ ์ปจํ ์ด๋์ 80๋ฒ ํฌํธ์ ๋งคํํ์ฌ, ์น ๋ธ๋ผ์ฐ์ ์์ http://localhost:8010์ผ๋ก ์ ๊ทผํ ์ ์๊ฒ ํฉ๋๋ค.
# nginx ์ปจํ
์ด๋๋ฅผ ๋ง๋ ๋ค.
toby@tobykakao:~$ docker run -d -p 8010:80 --name=webserver10 nginx:latest
0b423670cb26dfa30faea24f31c0539b7aa522fe017dc046deb69aeedbacbfa4
docker cp ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ์ปจํ ์ด๋ ๋ด๋ถ์ Nginx ์ค์ ํ์ผ์ ํธ์คํธ๋ก ๋ณต์ฌํฉ๋๋ค. ์ค์ ํ์ผ์ /etc/nginx/nginx.conf ๊ฒฝ๋ก์ ์์ผ๋ฉฐ, ์ด๋ฅผ ๋ก์ปฌ์ ํ์ฌ ๋๋ ํ ๋ฆฌ๋ก ๋ณต์ฌํ ์ ์์ต๋๋ค.
# nginx ์ปจํ
์ด๋์ nginx.conf๋ฅผ ํธ์คํธ๋ก ๋ณต์ฌํด ์จ๋ค.
toby@tobykakao:~$ docker cp webserver10:/etc/nginx/nginx.conf ./nginx.conf
Successfully copied 2.56kB to /home/toby/nginx.conf
์ด ๋ช ๋ น์ ํตํด nginx.conf ํ์ผ์ด ํธ์คํธ์ ํ์ฌ ๋๋ ํ ๋ฆฌ์ ๋ณต์ฌ๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ nginx.conf ํ์ผ์ ์์ ํ ํ, ๋์ผํ ๊ฒฝ๋ก๋ก ์ปจํ ์ด๋์ ๋ค์ ๋ณต์ฌํฉ๋๋ค.
# nginx ๊ตฌ์ฑ ์ ๋ณด๋ฅผ ๋ณ๊ฒฝํ๋ค๊ณ ๊ฐ์ ํ๋ค. ๋ค์ ์๋ ์์น์ ๋ณต์ฌํด ์ค๋ค.
toby@tobykakao:~$ docker cp nginx.conf webserver10:/etc/nginx/nginx.conf
Successfully copied 2.56kB to webserver10:/etc/nginx/nginx.conf
์ด ๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ์์ ๋ ์ค์ ํ์ผ์ด Nginx ์ปจํ ์ด๋์ ์๋ ์์น์ ๋ฎ์ด์ฐ๊ธฐ๋ฉ๋๋ค.
๋ํ Nginx ์ค์ ํ์ผ์ ๋ฐ์ํ๋ ค๋ฉด ์ปจํ ์ด๋๋ฅผ ์ฌ์์ํด์ผ ํฉ๋๋ค. docker restart ๋ช ๋ น์ด๋ฅผ ํตํด ์ปจํ ์ด๋๋ฅผ ์ฌ์์ํฉ๋๋ค. ์ด์ ์๋์ฒ๋ผ Nginx ์ปจํ ์ด๋๊ฐ ์ฌ์์๋์ด ์๋ก์ด ์ค์ ์ด ์ ์ฉ๋ฉ๋๋ค.
# nginx ์ปจํ
์ด๋๋ฅผ ์ฌ์์ํด ์ค๋ค.
toby@tobykakao:~$ docker restart webserver10
webserver10
docker run์ ์ฌ์ฉํด Nginx ์ปจํ ์ด๋ ์์ฑ.
docker cp๋ก Nginx ์ค์ ํ์ผ์ ํธ์คํธ๋ก ๋ณต์ฌ.
์์ ๋ ์ค์ ํ์ผ์ ๋ค์ ์ปจํ ์ด๋๋ก ๋ณต์ฌ.
docker restart๋ก Nginx ์ปจํ ์ด๋๋ฅผ ์ฌ์์ํ์ฌ ์ค์ ์ ์ฉ.
Node.js ํ ์คํธ ํ๊ฒฝ์ ์ํ ์ปจํ ์ด๋ ์คํ
Docker๋ฅผ ํ์ฉํ์ฌ Node.js ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค. Node.js ์ํ ์ฝ๋๋ฅผ ์์ฑํ๊ณ , Docker ์ปจํ ์ด๋์ ๋ณต์ฌํ ํ ์คํํ๋ ๊ณผ์ ์ ๋จ๊ณ๋ณ๋ก ๋ค๋ฃน๋๋ค.
๋จผ์ nodejs_test.js๋ผ๋ ํ์ผ์ ์์ฑํ๊ณ , HTTP ์๋ฒ๋ฅผ ๊ฐ๋จํ ์ค์ ํ๋ ์ฝ๋๋ฅผ ์์ฑํฉ๋๋ค.
# node.js ์ํ ์ฝ๋ ์คํ์ ์ํ ์ปจํ
์ด๋๋ฅผ ์์ฑํ๋ค.
toby@tobykakao:~$ vi nodejs_test.js
var http = require('http');
var content = function(req, resp) {
resp.end("Good morning Korea~!" + "\n");
resp.writeHead(200);
}
๋ค์์ผ๋ก Node.js Docker ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค. ์ต์ ๋ฒ์ ์ ์ฌ์ฉํ๋ ค๋ฉด docker pull node ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํฉ๋๋ค.
# node ์ปจํ
์ด๋๋ฅผ ์คํํ๋ค.
toby@tobykakao:~$ docker pull node
Using default tag: latest
latest: Pulling from library/node
c1e0ef7b956a: Already exists
95b894d63c77: Already exists
cb5594266b1b: Already exists
59d4884f8528: Already exists
dfd6b1d2546c: Pull complete
a4ac632c2863: Pull complete
0ce2f898cccf: Pull complete
478f75ada764: Pull complete
Digest: sha256:840dad0077213cadd2d734d542ae11cd0f648200be29504eb1b6e2c995d2b75a
Status: Downloaded newer image for node:latest
docker.io/library/node:latest
Node.js ์ปจํ ์ด๋๋ฅผ ์์ฑํ๊ณ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํํฉ๋๋ค. -p 8002:8002 ์ต์ ์ ํตํด ํธ์คํธ์ 8002 ํฌํธ๋ฅผ ์ปจํ ์ด๋์ 8002 ํฌํธ์ ๋งคํํฉ๋๋ค.
# ์์ค ์ฝ๋ ๋ณต์ฌ ํ ์คํํ๋ค.
toby@tobykakao:~$ docker run -d -it -p 8002:8002 --name=nodejs_test node
bb75f81042af805aebb73c63757adb595d5c308255650cd6126c164f9b0b1b45
toby@tobykakao:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb75f81042af node "docker-entrypoint.s\u2026" 4 seconds ago Up 3 seconds 0.0.0.0:8002->8002/tcp, :::8002->8002/tcp nodejs_test
0b423670cb26 nginx:latest "/docker-entrypoint.\u2026" 5 minutes ago Up 3 minutes 0.0.0.0:8010->80/tcp, [::]:8010->80/tcp webserver10
8d3a78363102 python "python3" 21 minutes ago Up 21 minutes 0.0.0.0:8900->8900/tcp, :::8900->8900/tcp python_test
๊ทธํ, ์์ฑํ nodejs_test.js ํ์ผ์ docker cp ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ nodejs_test ์ปจํ ์ด๋๋ก ๋ณต์ฌํฉ๋๋ค.
# ์์ค ์ฝ๋ ๋ณต์ฌ ํ ์คํํ๋ค.
toby@tobykakao:~$ docker cp nodejs_test.js nodejs_test:/nodejs_test.js
toby@tobykakao:~$ docker exec -it nodejs_test node /nodejs_test.js
์์์ ์์ฑํ ์ปจํ ์ด๋ ์ด๋ฆ์ด nodejs_test์ ๋๋ค. ๋ง์ฝ ์ปจํ ์ด๋ ์ด๋ฆ์ ๋ณ๊ฒฝํ๊ณ ์ถ๋ค๋ฉด docker rename์ ์ด์ฉํด์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ์ปจํ ์ด๋์ ์ด๋ฆ์ ์ฃผ์ง ์๊ณ ์์ฑํ ๊ฒฝ์ฐ์ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์ฐ๊ด๋ ์ด๋ฆ์ผ๋ก ๋ณ๊ฒฝํ ๊ฒฝ์ฐ, ์ปจํ ์ด๋์ ์คํ๊ณผ ์๊ด์์ด ๋์ ๋ณ๊ฒฝ์ด ๋๋ค.
# ๋ฐฉ์: docker rename <๊ธฐ์กด์ Container๋ช
> <์๋ก์ด Container๋ช
>
toby@tobykakao:~$ docker rename nodejs_test nodeapp
toby@tobykakao:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb75f81042af node "docker-entrypoint.s\u2026" 8 minutes ago Up 8 minutes 0.0.0.0:8002->8002/tcp, :::8002->8002/tcp nodeapp
0b423670cb26 nginx:latest "/docker-entrypoint.\u2026" 14 minutes ago Up 12 minutes 0.0.0.0:8010->80/tcp, [::]:8010->80/tcp webserver10
8d3a78363102 python "python3" 30 minutes ago Up 30 minutes 0.0.0.0:8900->8900/tcp, :::8900->8900/tcp python_test
docker commit์ ์์ฑํ ์ปจํ ์ด๋์ node ํ๋ก๊ทธ๋จ ํ๊ฒฝ๊ณผ ์ ์ฅํ ์์ค ์ฝ๋ ๊ทธ๋๋ก ์๋ก์ด ์ด๋ฏธ์ง๋ก ์์ฑํ ์ ์์ต๋๋ค.
์ผ๋ฐ์ ์ผ๋ก ๋์ปค ์ด๋ฏธ์ง๋ฅผ ํตํด ์ปจํ ์ด๋๋ฅผ ์์ฑํ์ง๋ง, docker commit์ ํตํด ์ปจํ ์ด๋๋ฅผ ์ด๋ฏธ์ง๋ก ์์ฑํ ์๋ ์์ต๋๋ค.
๋จผ์ nginx:latest ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํด Nginx ์ปจํ ์ด๋๋ฅผ ์คํํฉ๋๋ค.
toby@tobykakao:~$ docker run -it --name webserver8 -d -p 8008:80 nginx:latest
4bd32b7f867b4d6665d94fc5761a4840c96dc4566a0d3662b66854fad60459a5
toby@tobykakao:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bd32b7f867b nginx:latest "/docker-entrypoint.\u2026" 13 seconds ago Up 12 seconds 0.0.0.0:8008->80/tcp, [::]:8008->80/tcp webserver8
bb75f81042af node "docker-entrypoint.s\u2026" 10 minutes ago Up 10 minutes 0.0.0.0:8002->8002/tcp, :::8002->8002/tcp nodeapp
0b423670cb26 nginx:latest "/docker-entrypoint.\u2026" 15 minutes ago Up 13 minutes 0.0.0.0:8010->80/tcp, [::]:8010->80/tcp webserver10
8d3a78363102 python "python3" 31 minutes ago Up 31 minutes 0.0.0.0:8900->8900/tcp, :::8900->8900/tcp python_test
๋จผ์ nginx:latest ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํด Nginx ์ปจํ ์ด๋๋ฅผ ์คํํฉ๋๋ค.
# index.html ํ์ผ ์์
toby@tobykakao:~$ vi index.html
# curl localhost:8008์ ํตํด ์ ์ ๋์์ ํ์ธํ๋ค.
toby@tobykakao:~$ curl localhost:8008
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
๊ทธํ, ์ปจํ ์ด๋ ๋ด๋ถ์ index.html ํ์ผ์ ์์ ํ๊ธฐ ์ํด ๋ค์๊ณผ ๊ฐ์ด ํธ์คํธ์์ ์์ ํ ํ์ผ์ ์ปจํ ์ด๋๋ก ๋ณต์ฌํ ์ ์์ต๋๋ค.
# ๋์ปค cp ๋ช
๋ น์ด๋ก ํ์ผ ๋ณต์ฌ
toby@tobykakao:~$ docker ps index.html webserver8:/usr/share/nginx/html/index/html
"docker ps" accepts no arguments.
See 'docker ps --help'.
Usage: docker ps [OPTIONS]
List containers
์ปจํ ์ด๋ ๋ด์์ ํ์ผ์ด๋ ๋๋ ํฐ๋ฆฌ๊ฐ ์ถ๊ฐ, ์ญ์ , ๋๋ ์์ ๋์๋์ง ํ์ธํ๋ ค๋ฉด docker diff ๋ช ๋ น์ ์ฌ์ฉํฉ๋๋ค.
์์์ C๋ ๋ณ๊ฒฝ๋จ, A๋ ์ถ๊ฐ๋จ, D๋ ์ญ์ ๋จ์ ๋ํ๋ ๋๋ค.
# ์ถ๊ฐ๋ ์น ์์ค ๋ณ๊ฒฝ ์ ๋ณด๋ฅผ ํ์ธํ๋ ค๋ฉด docker diff(difference) ๋ช
๋ น์ ํตํด ๊ฐ๋ฅํ๋ค.
# docker diff๋ ํ์ผ ๋ฐ ๋๋ ํฐ๋ฆฌ์ ๋ชจ๋ ๋ณ๊ฒฝ ์ ๋ณด๋ฅผ ์ถ์ ํ๋ค.
# ์ ์ด์ ํค์๋๋ A(์ถ๊ฐ), D(์ญ์ ), C(๋ณ๊ฒฝ)๋ฅผ ์๋ฏธํ๋ค.
toby@tobykakao:~$ docker diff webserver8
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
A /var/cache/nginx/scgi_temp
A /var/cache/nginx/uwsgi_temp
A /var/cache/nginx/client_temp
C /etc
C /etc/nginx
C /etc/nginx/conf.d
C /etc/nginx/conf.d/default.conf
C /run
๋ณ๊ฒฝ๋ ๋ด์ฉ์ ์๋ก์ด Docker ์ด๋ฏธ์ง๋ก ์ ์ฅํ๊ธฐ ์ํด docker commit ๋ช ๋ น์ ์ฌ์ฉํฉ๋๋ค. -a ์ต์ ์ ์ฌ์ฉํ์ฌ ์์ฑ์๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
# docker commit์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ค. ์ด๋ -a(author)๋ ์์ฑํ ์ฌ๋์ ์ด๋์
์ด๋ค.
toby@tobykakao:~$ docker commit -a "kakao" webserver8 webfront:1.0
sha256:09366d99740ca4b93678281409da85a04376a544a4f5fee5d5b842b57ee076fe
# ์ด๋ฏธ์ง ํ์ธ
toby@tobykakao:~$ docker images | grep webfront
webfront 1.0 09366d99740c 24 seconds ago 197MB
toby@tobykakao:~$
์ด๋ฏธ์ง๋ฅผ Docker Hub์ ์ ๋ก๋ํ๊ธฐ ์ํด ๋จผ์ Docker Hub์ ๋ก๊ทธ์ธํฉ๋๋ค. Docker Hub์ ์ ๋ก๋ํ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํด ์๋ก์ด ์ปจํ ์ด๋๋ฅผ ์คํํ๊ณ , ์ ์์ ์ผ๋ก ์๋ํ๋์ง curl ๋ช ๋ น์ด๋ก ํ์ธํฉ๋๋ค.
# ๋ณธ์ธ์ ๋์ปค ํ๋ธ ์ ์ฅ์์ ์ฌ๋ ค๋ณธ๋ค.
toby@tobykakao:~$ docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /home/toby/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credential-stores
Login Succeeded
toby@tobykakao:~$ docker tag webfront:1.0 daehyunbigbread/webfront:1.0
toby@tobykakao:~$ docker push daehyunbignread/webfront:1.0
The push refers to repository [docker.io/daehyunbignread/webfront]
An image does not exist locally with the tag: daehyunbignread/webfront
# ํธ์ํ ์ด๋ฏธ์ง๋ก ์ ๋์ํ๋์ง ํ์ธํด ๋ณด์.
toby@tobykakao:~$ docker run -it --name webserver9 -d -p 8009:80 ๋ณธ์ธID/webfront:1.0
toby@tobykakao:~$ curl localhost:8009
Node.js ์ํ ์ฝ๋๋ฅผ ์์ฑํ์ฌ ์ปจํ ์ด๋ ๋ด๋ถ๋ก ๋ณต์ฌ.
docker pull์ ํตํด Node.js ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋.
docker run์ผ๋ก Node.js ์ปจํ ์ด๋๋ฅผ ์์ฑํ๊ณ ํฌํธ๋ฅผ ๋งคํ.
์ปจํ ์ด๋ ๋ด์์ Node.js ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํ.
Nginx ์ปจํ ์ด๋ ์์ฑ ๋ฐ ํ์ผ ์์ .
docker diff ๋ช ๋ น์ผ๋ก ๋ณ๊ฒฝ ์ฌํญ ํ์ธ.
๋ณ๊ฒฝ๋ ์ปจํ ์ด๋ ์ํ๋ฅผ ์๋ก์ด ์ด๋ฏธ์ง๋ก ์ปค๋ฐ.
Docker Hub์ ์ด๋ฏธ์ง ํธ์.
ํธ์ํ ์ด๋ฏธ์ง๋ก ์๋ก์ด ์ปจํ ์ด๋๋ฅผ ์คํํ๊ณ ํ ์คํธ.
'โ๏ธ Cloud Native > ๐ณ Docker' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Docker] Container์ ์ด๋ฏธ์ง (0) | 2025.01.10 |
---|---|
[Docker] Docker Volume ํ์ฉ (0) | 2024.11.16 |
[Docker] Docker Container ๋ช ๋ น์ด (with Ngnix Container ์คํ) (0) | 2024.11.05 |
[Docker] Docker ๋ช ๋ น์ด ํ์ฉ Part.2 (0) | 2024.10.31 |
[Docker] Docker ๋ช ๋ น์ด ํ์ฉ Part.1 (0) | 2024.10.31 |