[우분투서버] SSH접속시
우분투 생성 시 기본 유저 네임 ubuntu
sudo apt-get update
sudo apt-get install docker.io -y
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
위 설정후 세션을 재시작합니다.
ubuntu@ip-172-31-0-83:~$ 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
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enX0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc fq_codel state UP group default qlen 1000
link/ether 02:af:42:c6:d2:19 brd ff:ff:ff:ff:ff:ff
inet 172.31.0.83/20 metric 100 brd 172.31.15.255 scope global dynamic enX0
valid_lft 2682sec preferred_lft 2682sec
inet6 fe80::af:42ff:fec6:d219/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:03:63:b5:72 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
172.31.0.x 대역대는 AWS CIDR에서 설정해둔 프라이빗 IP
ubuntu@ip-172-31-0-83:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
07a6c75c1a9f nginx "/docker-entrypoint.…" 8 minutes ago Exited (137) 42 seconds ago eloquent_benz
-d명령어로 데몬을 실행하고 포트 포워딩 하여 다시 생성함
ubuntu@ip-172-31-0-83:~$ docker run -d --name mynginx -p 80:80 nginx
f61bab4a6bac38f7b2efbdc50b442bec170b0f47def8d4c00e6a44a67bde97f0
docker exec -it mynginx bash
bash셀 형태로 접속함
bash안에서 vi 실행하는법
bash 쉘안에서 apt-get install vim 처음엔 실행되지않는 문제가 있음
아래와같이 apt-get udpate 수행한다.
apt-get update
apt-get install vim
vi 설치후 /usr/share/nginx/html/index.html 파일을 수정한다.
root@f61bab4a6bac:/usr/share/nginx/html# pwd
/usr/share/nginx/html
수정된 모습
[inspect nginx] 정보
ubuntu@ip-172-31-0-83:~$ docker image inspect nginx
[
{
"Id": "sha256:60c8a892f36faf6c9215464005ee6fb8cf0585f70b113c0b030f6cb497a41876",
"RepoTags": [
"nginx:latest"
],
"RepoDigests": [
"nginx@sha256:bc5eac5eafc581aeda3008b4b1f07ebba230de2f27d47767129a6a905c84f470"
],
"Parent": "",
"Comment": "buildkit.dockerfile.v0",
"Created": "2024-10-02T17:55:35Z",
"Container": "",
"ContainerConfig": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"DockerVersion": "",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.27.2",
"NJS_VERSION=0.8.6",
"NJS_RELEASE=1~bookworm",
"PKG_RELEASE=1~bookworm",
"DYNPKG_RELEASE=1~bookworm"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"ArgsEscaped": true,
"Image": "",
"Volumes": null,
"WorkingDir": "/",
"Entrypoint": [
"/docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
},
"StopSignal": "SIGQUIT"
},
"Architecture": "amd64",
"Os": "linux",
"Size": 191670156,
"VirtualSize": 191670156,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/53f202f0991c93531eb064b4bf4e1e17eea0bc696635cbd7fbd0f04c619dc576/diff:/var/lib/docker/overlay2/cc32ddf5fbc9b9f136b06592fc389784f2fa935dc15f1a210bc5c99f535c27bc/diff:/var/lib/docker/overlay2/2f3bd6c0cecc111c6519bccdee97f301f3aa94b9191dcd3ddb3d2f65a49b7822/diff:/var/lib/docker/overlay2/d0a943f2db76e917f3b4185fe286c2611389f257367247f254b36171d662d597/diff:/var/lib/docker/overlay2/1fa930db01c66e3fec33e34a1842d7677d4a3d7282face9d1ae3f1cb24052cef/diff:/var/lib/docker/overlay2/60b84d3e24b39625ad8c1ed8097e8bd0a2edfcc4a89fe0124754adddfa256a97/diff",
"MergedDir": "/var/lib/docker/overlay2/f3163d896f19a78832e8c577f5b932eb753f504ac97effa28ea53c50a2aef088/merged",
"UpperDir": "/var/lib/docker/overlay2/f3163d896f19a78832e8c577f5b932eb753f504ac97effa28ea53c50a2aef088/diff",
"WorkDir": "/var/lib/docker/overlay2/f3163d896f19a78832e8c577f5b932eb753f504ac97effa28ea53c50a2aef088/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:c3548211b8264f8bfa47a6727043a64f1791b82ac965a284a7ea187e971a95e2",
"sha256:7dca41ff148690a71f3a18230b037c224699bddca66451edfc3e0875c38266a5",
"sha256:ffe4285e29068b1a6112d99b633535058b91344bb1eac41cbec3c319c908cc43",
"sha256:19b722697f76432e2991f3ddbfe83ff062c58cbc81ae86a209cc1a907281ed33",
"sha256:a1fe8b721bb198a7416c45774b913499e3d32da7e49c36a173ab9eab1f16f651",
"sha256:a0c145a29c8d0bd6496ca844601ea021aaeef71ab28a060cc9b4e3f0031d2eb6",
"sha256:61ef4e878aac3937fc88785022b0a2b9b7791455b3a34b72eb5a77fd1bdbc7fd"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
ubuntu@ip-172-31-0-83:~$
"Env" ,"Cmd -> 실행정보가 null
[nginx] 데몬으로 실행되지않도록 남겨진 옵션확인
ubuntu@ip-172-31-0-83:~$ docker run -d -p 8080:80 --name newnginx nginx:latest
d9a9590a3431bbe5c9774eb602ef263cc0e6e8345dcca401648837a2deb8f03c
이미 80포트에 있으니 8080으로 만든다.
docker inspect newnginx
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0846f90bbbad33a91c642c6781858db4222ef813cb8ae9315fc2f52360eff1ee",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
},
{
"HostIp": "::",
"HostPort": "8080"
}
]
]
네트워크
new nginx 172.17.0.3
네트워크 mynginx 172.17.0.2
docker ps
ubuntu@ip-172-31-0-83:~$ docker rm newnginx
Error response from daemon: You cannot remove a running container d9a9590a3431bbe5c9774eb602ef263cc0e6e8345dcca401648837a2deb8f03c. Stop the container before attempting removal or force remove
docker logs -f --tail 5 mynginx
ubuntu@ip-172-31-0-83:~$ docker logs -f --tail 5 mynginx
169.211.207.102 - - [19/Nov/2024:03:15:21 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" "-"
169.211.207.102 - - [19/Nov/2024:03:15:21 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" "-"
169.211.207.102 - - [19/Nov/2024:03:15:22 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" "-"
169.211.207.102 - - [19/Nov/2024:03:15:22 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" "-"
169.211.207.102 - - [19/Nov/2024:03:15:22 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" "-"
[네트워크 확인하기]
ubuntu@ip-172-31-0-83:~$ docker network ls
NETWORK ID NAME DRIVER SCOPE
df24891add35 bridge bridge local
fad9e1fb4845 host host local
fc99e0719dd4 none null local
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"ed893671176bf5a2ecf4db35b81a236802b25a0c37e2a1379264c867f2d6b55c": {
"Name": "newnginx",
"EndpointID": "c184a21ad312d23fdcc0b7a4e8a02f4a7324674b6baf84d12899fb77847a2ac8",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"f61bab4a6bac38f7b2efbdc50b442bec170b0f47def8d4c00e6a44a67bde97f0": {
"Name": "mynginx",
"EndpointID": "15d119b693acaf3305de3d4b8a432b900c88f4e8e42720ddbda0ba71992e4581",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
bash shell에서 ping 다운로드하기
root@f61bab4a6bac:/# apt-get install iputils-ping
[ping테스트]
--- 172.17.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.022/0.023/0.024/0.001 ms
root@f61bab4a6bac:/# ping 172.17.0.1 // 게이트웨이 테스트
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.051 ms
root@f61bab4a6bac:/# ping 172.17.0.2 // mynginx
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.024 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.022 ms
^C
^C
--- 172.17.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.051/0.051/0.051/0.000 ms
root@f61bab4a6bac:/# ping 172.17.0.3 // newnginx
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.106 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.061 ms
같은 네트워크 상에 있어서 통신이 가능한 모습임
ubuntu@ip-172-31-0-83:~$ sudo docker network create mynetwork
88d00ee21b6e92bb87a21b49bd2bddfdb9832a352c3b781c69c4d0422bdcfd6b
//네트워크 생성완료
ubuntu@ip-172-31-0-83:~$
ubuntu@ip-172-31-0-83:~$ docker run -d -p 8081:80 --net=mynetwork --name netnginx nginx
7ca532bb772af976c18ad0fa97f50687c6a3c7b66856341b69175d4f55326f18
//도커런
ubuntu@ip-172-31-0-83:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ca532bb772a nginx "/docker-entrypoint.…" 3 seconds ago Up 2 seconds 0.0.0.0:8081->80/tcp, :::8081->80/tcp netnginx
ed893671176b nginx:latest "/docker-entrypoint.…" 17 minutes ago Up 17 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp newnginx
f61bab4a6bac nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp, :::80->80/tcp mynginx
/home/ubuntu/.docker/config.json
echo config.json 내용== | base64 -d
ubuntu@ip-172-31-0-83:~/.docker$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ed893671176b nginx:latest "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8080->80/tcp, :::8080->80/tcp newnginx
f61bab4a6bac nginx "/docker-entrypoint.…" 4 hours ago Up 4 hours 0.0.0.0:80->80/tcp, :::80->80/tcp mynginx
ubuntu@ip-172-31-0-83:~/.docker$ docker rm -f newnginx
newnginx
ubuntu@ip-172-31-0-83:~/.docker$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f61bab4a6bac nginx "/docker-entrypoint.…" 4 hours ago Up 4 hours 0.0.0.0:80->80/tcp, :::80->80/tcp mynginx
ubuntu@ip-172-31-0-83:~/.docker$
반응형
'클라우드 > Docker' 카테고리의 다른 글
[docker] devops/컨테이너 (0) | 2024.11.25 |
---|---|
[docker] volume 개념 설명하기 (0) | 2024.11.25 |
[docker] 기본개념 및 동작 (2) | 2024.11.20 |
Docker 명령어 정리 (1) | 2024.11.17 |
[DB] 1단계 MYSQL & DOCKER 마이그레이션 해보기 (2) | 2024.11.16 |