--interactive ; -i : ํ์ค ์
๋ ฅ์ ์ฐ๋ค
--tty ; -t : ํฐ๋ฏธ๋์ ์ฌ์ฉํ๋ค.
-> -it
โ๏ธ ์ปจํ ์ด๋ ํ๋ฒ์ ์ง์ฐ๊ธฐ
# docker ps -a // docker container ls -a ์ค์
# # docker rm -f $(docker ps -a -q)
โ๏ธ ์ด๋ฏธ์ง ์ง์ฐ๊ธฐ
# docker image rm nginx //ID ๋ฃ์ด๋ ๋๊ณ ์ปจํ
์ด๋๊ฐ ์ง์์ ธ์ผ ์ด๋ฏธ์ง๊ฐ ์ง์์ง.
# docker rmi centos:latest //image rm ์ค์ ; rmi
# docker rmi ID ID ID // ์ด๋ฏธ์ง ์ฌ๋ฌ๊ฐ ์ญ์
# docker images // docker image ls ์ค์
# docker rmi $(docker images -q) // ์ด๋ฏธ์ง ํ๋ฒ์ ์ง์ฐ๊ธฐ
docker images -q ; ์ด๋ฏธ์ง๋ค์ ์์ด๋ ๋ชจ๋ ์ถ๋ ฅ
โ๏ธ ๋ช ๋ น์ด run --rm
# docker run --name test_cal centos:7 /bin/cal
# docker run --name test_cal1 --rm centos:7 /bin/cal //์คํ ํ ๋ฐ๋ก ์ญ์ ํ๋ ์ต์
์ถ๊ฐํด์ ๋ง๋ค์ด๋ณด๊ธฐ (--rm)
โ๏ธ ๋ช ๋ น์ด run -it
# docker run -t --name test_bash centos:7 /bin/bash // t๋ง ์ ์ฉ -> ๋ช
๋ น์ด ์๋จนํ. (์ํธ์์ฉ X) > i๋ฅผ ๋ฃ์ด์ค์ผ ํจ.
# docker run -i --name test_bash1 centos:7 /bin/bash //๋ค์ด๊ฐ์ง๊ธด ํ๋๋ฐ ํฐ๋ฏธ๋์ด ์ ๋๋ก ์๋์ด ์์์ฐฎ์.
# docker run -it --name test_bash2 centos:7
โ๏ธ ๋ช ๋ น์ด run -d, ์์ํ ๋น
[root@localhost ~]# docker run -d --name
test_ping centos:7 /bin/ping localhost
b7714d2a46e2117539a8befb878c78699fc06197551195fe52b8dafecf2eef27
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0baf49feca26 centos:7 "/bin/ping localhost" 5 minutes ago Up 5 minutes test_ping
1942b02ee487 centos:7 "/bin/bash" 11 minutes ago Up 11 minutes test_bash1
41c5cfdd0b8a centos:7 "/bin/bash" 14 minutes ago Up 14 minutes test_bash
# docker run -d -p 8080:80 --name test_port nginx
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1da2c26d3b56 nginx "/docker-entrypoint.โฆ" 56 seconds ago Up 54 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp test_port
0baf49feca26 centos:7 "/bin/ping localhost" 6 minutes ago Up 6 minutes test_ping
1942b02ee487 centos:7 "/bin/bash" 12 minutes ago Up 12 minutes test_bash1
41c5cfdd0b8a centos:7 "/bin/bash" 16 minutes ago Up 16 minutes test_bash
# docker stats test_port
-> 192.168.1.91:8080
(docker server IP):ํฌํธ๋ฒํธ๋ก ๋ค์ด๊ฐ์ ์๋ก๊ณ ์นจ ํตํด์ CPU ์ฌ์ฉ๋ ์ฌ๋ ค๋ณด๊ธฐ
โ๏ธ ๋ช ๋ น์ด run - ์์ํ ๋น ๋ฐ ๋ง์ดํธ
# docker run -d -p 8181:80 --cpus 1 --memory 256m --name test_sesource nginx
# docker stats test_sesource //๋ฉ๋ชจ๋ฆฌ ํ ๋น ํ์ธ
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
5fff17ecd5d1 test_sesource 0.00% 1.973MiB / 256MiB 0.77% 656B / 0B 0B / 6.66kB 3
# docker run -d -p 8282:80 --cpus 1 --memory 512m -v /tmp:/usr/share/nginx/html --name volume-container nginx // ๋ณผ๋ฅจ์ ๋์ปค ์๋ฒ tmpํด๋์ ๋ง์ดํธํ ์ปจํ
์ด๋ ์์ฑ
[root@localhost tmp]# cat index.html
hello world
[root@localhost tmp]#
โ๏ธ ์ปจํ ์ด๋ ๋ชฉ๋ก ํ ์ด๋ธ, ํํฐ ์ด์ฉํด์ ํ์ธํ๊ธฐ
[root@localhost tmp]# docker ps -a --format "table {{.Command}}\t{{.Ports}}"
COMMAND PORTS
"/docker-entrypoint.โฆ" 0.0.0.0:8282->80/tcp, :::8282->80/tcp
"/docker-entrypoint.โฆ" 0.0.0.0:8181->80/tcp, :::8181->80/tcp
"/docker-entrypoint.โฆ" 0.0.0.0:8080->80/tcp, :::8080->80/tcp
"/bin/ping localhost"
"/bin/bash"
"/bin/bash"
"/bin/cal"
[root@localhost tmp]# docker ps -a -f name=test_bash //ํํฐ์ฌ์ฉ
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1942b02ee487 centos:7 "/bin/bash" 45 minutes ago Up 45 minutes test_bash1
41c5cfdd0b8a centos:7 "/bin/bash" 48 minutes ago Up 48 minutes test_bash
[root@localhost tmp]#
โ๏ธ ๋ช ๋ น์ด exec
[root@localhost tmp]# docker exec -it test_bash /bin/bash
[root@41c5cfdd0b8a /]#
[root@41c5cfdd0b8a /]#
[root@41c5cfdd0b8a /]#
[root@41c5cfdd0b8a /]#
[root@41c5cfdd0b8a /]#
โ๏ธ ๋ช ๋ น์ด rename
[root@localhost tmp]# docker rename test_port webserver
[root@localhost tmp]# docker ps -a -f name=webserver
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1da2c26d3b56 nginx "/docker-entrypoint.โฆ" 43 minutes ago Up 43 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp webserver
โ๏ธ ๋ช ๋ น์ด cp
[root@localhost tmp]# cd ~
[root@localhost ~]# ls
[root@localhost ~]# docker cp webserver:/usr/share/nginx/html/index.html /root/in dex.html
[root@localhost ~]# vi index.html
nginx -> apache๋ก ์์
[root@localhost ~]# docker cp ./index.html webserver:/usr/share/nginx/html/index.html
ํ์ธ
[root@localhost ~]# ls
food.tar index.html
[root@localhost ~]# tar -xvf food.tar -C html
[root@localhost ~]# ls html/
assets index.html vendors
[root@localhost ~]# docker cp ./html webserver:/usr/share/nginx //ํด๋ ์ด๋
ํ์ธ
โ๏ธ ๋ช ๋ น์ด diff
[root@localhost ~]# docker diff webserver
C ; change
A ; add
D ; delete
โ๏ธ ๋ช ๋ น์ด commit
[root@localhost ~]# docker commit -a "mj<test@example.com>" -m "FOOD" webserver test_commit:v1.0
sha256:f266d80886c08f6a95a40836d40dba7b82c728c25140dd08dbcd5b78065f6476
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test_commit v1.0 f266d80886c0 About a minute ago 170MB
nginx latest 55f4b40fe486 2 weeks ago 142MB
centos 7 eeb6ee3f44bd 9 months ago 204MB
โ๏ธ ๋ช ๋ น์ด save
[root@localhost ~]# docker save -o test_commit.tar test_commit:v1.0
[root@localhost ~]# ls
food.tar html index.html test_commit.tar
bridge๋ ๊ณง docker 0
9: vethc3636e7@if8
veth14545c8@if10
veth0d6750f@if14
veth1e61a64@if16
veth23c2690@if20
# ip a
ํ์ ๋ veth~๊ฐ ์ปจํ ์ด๋๋ ์ฐ๊ฒฐ๋์ด์๋ ์ ๋ณด๋ค. (up๋์ด์๋ ์ปจํ ์ด๋๋ง ๋์ด)
[root@localhost ~]# docker exec -it test_bash /bin/bash
[root@41c5cfdd0b8a /]# yum install -y net-tools // ifconfig์ค์น . ํ ํ์ ์์์..
[root@41c5cfdd0b8a /]# yum install -y iproute // ip a ์ค์น
[root@41c5cfdd0b8a /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
8; ๋ฐ๊นฅ ๊ฐ์ ์ค์์น ํฌํธ ๋ฒํธ / 9; ๋ด๋ถ ๋์นด๋
โ๏ธ ๋ช ๋ น์ด network ; network๋ง๋ค๊ธฐ
[root@localhost ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
29e67c759ba3 bridge bridge local //docker0
a8ae279c0395 host host local
dd00f8d63e73 none null local
[root@localhost ~]# docker inspect bridge //inspect; ์์ธํ๊ฒ ๋ณด๊ธฐ
[root@localhost ~]# docker network create -d bridge --subnet 192.168.123.3/24 --ip-range 192.168.123.128/25 test_bridge //-d; driver , test_bridge: ๋คํธ์ํฌ ์ด๋ฆ.
[root@localhost ~]# docker inspect bridge
[root@localhost ~]# docker run -d -p 8383:80 --name webserver1 --network test_bridge nginx
[root@localhost ~]# docker network connect test_bridge test_bash
[root@localhost ~]# docker inspect test_bash
[root@localhost ~]# docker network disconnect test_bridge test_bash
[root@localhost ~]# docker network connect test_bridge test_bash
[root@localhost ~]# docker network connect test_bridge webserver
[root@localhost ~]# docker exec -it test_bash /bin/bash
[root@41c5cfdd0b8a /]# ping webserver //๊ฐ์ ๋คํธ์ํฌ์์๋ ์ปจํ
์ด๋ ์ด๋ฆ์ด ๋๋ฉ์ธ์ฒ๋ผ ์ฌ์ฉ๋ ์ ์์.
PING webserver (172.17.0.5) 56(84) bytes of data.
64 bytes from webserver.bridge (172.17.0.5): icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from webserver.bridge (172.17.0.5): icmp_seq=2 ttl=64 time=0.044 ms
-> ip๋ฐ๋์ด๋ ๊ฐ์ ๋คํธ์ํฌ ์์์๋ ์ปจํ ์ด๋ ์ด๋ฆ์ผ๋ก ํต์ ๊ฐ๋ฅํ๋ค. (๋๋ฉ์ธ์ฒ๋ผ)
https://hub.docker.com/_/mariadb Environment Variables์ฐธ๊ณ
โ๏ธ db์๋ฒ(์ปจํ ์ด๋)์์ฑ
[root@localhost ~]# docker run -d -p 3306:3306 --name dbserver \
-e MYSQL_DATABASE=wordpress \
-e MYSQL_USER=wpuser \
-e MYSQL_PASSWORD=wppass \
-e MYSQL_ROOT_PASSWORD=password --network test_bridge mariadb
โ๏ธ ์น์๋ฒ(์ปจํ ์ด๋) ์์ฑ
[root@localhost ~]# docker run -itd -p 8888:80 --name apache --network test_bridge centos:7
[root@localhost ~]# docker exec -it apache bash
[root@4858727d043d /]# yum install -y httpd php php-mysql php-gd php-mbstring wget unzip
[root@4858727d043d /]# wget https://ko.wordpress.org/wordpress-4.8.2-ko_KR.zip
[root@4858727d043d /]# cd /var/www/html
[root@4858727d043d html]# unzip /wordpress-4.8.2-ko_KR.zip
[root@4858727d043d html]# mv wordpress/* .
[root@4858727d043d html]# chown -R apache:apache /var/www/*
[root@4858727d043d html]# httpd &
->์ํฐ
[root@4858727d043d html]# ping dbserver
PING dbserver (192.168.123.132) 56(84) bytes of data.
64 bytes from dbserver.test_bridge (192.168.123.132): icmp_seq=1 ttl=64 time=0.090 ms
64 bytes from dbserver.test_bridge (192.168.123.132): icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from dbserver.test_bridge (192.168.123.132): icmp_seq=3 ttl=64 time=0.044 ms
์ค๋ฌดํนํ pdf 77๋ฒ์ฌ๋ผ์ด๋ ์ฐธ๊ณ
[root@localhost ~]# docker tag test_commit:v1.0 mj030kk/test_commit:v1.0
//๋ณ์นญ ๋ฌ๊ธฐ
//์ฒ์ commitํ ๋๋ถํฐ ์ด๋ฏธ์ง ์ด๋ฆ ์์ dockerhubID/ ํด์ฃผ๋ฉด ํ๊ทธ ๋ฐ๋ก ํ ํ์ ์์.
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test_commit v1.0 f266d80886c0 4 hours ago 170MB
mj030kk/test_commit v1.0 f266d80886c0 4 hours ago 170MB
nginx latest 55f4b40fe486 2 weeks ago 142MB
mariadb latest ea81af801379 4 weeks ago 383MB
centos 7 eeb6ee3f44bd 9 months ago 204MB
[root@localhost ~]# docker login
Login with your Docker ID 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.
Username: mj030kk
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
[root@localhost ~]# docker push mj030kk/test_commit:v1.0
root@ubuntu-node02:~# sudo apt update
root@ubuntu-node02:~# sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
root@ubuntu-node02:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
root@ubuntu-node02:~# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
root@ubuntu-node02:~# sudo apt update
root@ubuntu-node02:~# sudo apt-cache policy docker-ce
root@ubuntu-node02:~# sudo apt install docker-ce -y
root@ubuntu-node02:~# docker run -d -p 80:80 --name webserver mj030kk/test_commit:v1.0
์ค๋ฌดํนํ pdf 74~
[root@localhost ~]# mkdir test
[root@localhost ~]# cd test
[root@localhost test]# vi Dockerfile
FROM ubuntu:18.04
MAINTAINER mj@example.com
LABEL "name"="webserver"
ENV aloha=date
ENV path=/var/www/html
RUN sed -i 's/archive.ubuntu.com/ftp.daumkakao.com/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get install apache2 -y
COPY nihao /var/www/html/nihao
COPY hello.html $path
ADD aws.tar /var/www/html
WORKDIR /var/www/html
RUN echo ohayo >> ohayo.html
VOLUME /var/www/html
EXPOSE 80
ENTRYPOINT ["apachectl"]
CMD ["-D", "FOREGROUND"]
๐โ๏ธโ๏ธ๐ขโญ๏ธ๐