안녕하세요 리눅스 초보 입니다.^^;;;
리눅스를 업무상 급하게 맡게 되어서 여러가지 해보고 있는데
도커 내부 컨테이너 서비스만 외부 접속이 되지 않습니다.
서버 피씨가 리눅스 머신( centos 7 )
방화벽 해제한 상태이고 해당 머신에서 서비스 포트 19999/5000/4777/80/443 등등 다 접속 잘됨.
도커 설치 - 도커 portainer 공식 홈피 설명대로 실행.
외부 접속 불가
내부 리눅스 머신 에서는 해당 포트 9000 텔넷 연결 잘됨
짐작키로는 내부 에서는 잘 접속되지만 외부에서 도커 내부로만 안됨.
방화벽 말고 연관있는 것이 또 있을까요?
도커 포테이너 런 명령어
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
우선 해보니 1 입니다. ^^;;
net.ipv4.ip_forward =1
net.ipv4.ip_forward_use_pmtu = 0
이렇게 나옵니다.
일단 아래 새로단 리플이 있구요...
도커 로그 확인 해보니
마이 아파치 앱은
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,
using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Wed Mar 11 23:54:41.780019 2020] [mpm_event:notice] [pid 1:tid 140000488514688] AH00489: Apache/2.4.41 (Unix) configured -- resuming normal operations
[Wed Mar 11 23:54:41.780794 2020] [core:notice] [pid 1:tid 140000488514688] AH00094: Command line: 'httpd -D FOREGROUND'
이런 로그가....
있습니다. 이게 어떤건지는 몰라서 서버네임 관련 에러 인건지....궁금합니다.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
833aea73d4be portainer/portainer "/portainer" 12 seconds ago Up 11 seconds 0.0.0.0:9000->9000/tcp portainer
tcp6 0 0 :::9000 :::* LISTEN 2192/docker-proxy
121547bdf628 httpd:2.4 "httpd-foreground" 42 seconds ago Up 40 seconds 0.0.0.0:8080->80/tcp my-apache-app
이렇게 생성이 되었고,
tcp6 0 0 :::8080 :::* LISTEN 2901/docker-proxy
포트 리슨 하고 있는데,
curl localhost:8080
이것은 실패가 나네요 ...
curl: (56) Recv failure: Connection reset by peer
당연히 외부에서 telnet ip 8080 안됩니다.
그렇다면 네트워크 관련 이슈가 아닌 도커 내부 에러 일까요? ㅜㅜ
pkts bytes target prot opt in out source destination
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
39 1976 DOCKER-USER all -- any any anywhere anywhere
39 1976 DOCKER-ISOLATION-STAGE-1 all -- any any anywhere anywhere
0 0 ACCEPT all -- any docker0 anywhere anywhere ctstate RELATED,ESTABLISHED
39 1976 DOCKER all -- any docker0 anywhere anywhere
0 0 ACCEPT all -- docker0 !docker0 anywhere anywhere
0 0 ACCEPT all -- docker0 docker0 anywhere anywhere
Chain OUTPUT (policy ACCEPT 146 packets, 63235 bytes)
pkts bytes target prot opt in out source destination
Chain DOCKER (1 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- !docker0 docker0 anywhere 172.17.0.2 tcp dpt:cslistener
0 0 ACCEPT tcp -- !docker0 docker0 anywhere 172.17.0.3 tcp dpt:http
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
pkts bytes target prot opt in out source destination
0 0 DOCKER-ISOLATION-STAGE-2 all -- docker0 !docker0 anywhere anywhere
39 1976 RETURN all -- any any anywhere anywhere
Chain DOCKER-ISOLATION-STAGE-2 (1 references)
pkts bytes target prot opt in out source destination
0 0 DROP all -- any docker0 anywhere anywhere
0 0 RETURN all -- any any anywhere anywhere
Chain DOCKER-USER (1 references)
pkts bytes target prot opt in out source destination
39 1976 RETURN all -- any any anywhere anywhere
root 1082 1 0 Mar11 ? 00:00:00 /usr/sbin/gssproxy -D
root 10042 2772 0 00:54 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.3 -container-port 80
root 16533 2772 0 01:59 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9000 -container-ip 172.17.0.2 -container-port 9000
root 16782 2627 0 02:01 pts/0 00:00:00 grep --color=auto proxy
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.51 seconds
Starting Nmap 6.40 ( http://nmap.org ) at 2020-03-12 02:04 UTC
Nmap done: 1 IP address (0 hosts up) scanned in 0.50 seconds
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
5000/tcp open upnp
8080/tcp open http-proxy
9000/tcp open cslistener
nmap -sT 172.17.0.3
Starting Nmap 6.40 ( http://nmap.org ) at 2020-03-12 02:27 UTC
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.51 seconds
tarting Nmap 6.40 ( http://nmap.org ) at 2020-03-12 02:29 UTC
Nmap scan report for *.*.*.* -> ip 는 가렸습니다.;;;
Host is up (0.00068s latency).
Not shown: 995 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
8080/tcp open http-proxy
9000/tcp open cslistener
MAC Address: 1C:1B:0D:3B:C6:FF (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
docker ps 입니다.
그리고 8080 -> 80 바인드니 8080 오픈은 맞아보입니다.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b43b6cf9142 portainer/portainer "/portainer" 48 minutes ago Up 2 minutes 0.0.0.0:9000->9000/tcp great_murdock
90822c20f0c9 httpd:2.4 "httpd-foreground" 2 hours ago Up 2 hours 0.0.0.0:8080->80/tcp my-apache-app
서버 머신 자체에서 telnet 9000/8080 -> 도커 컨테이너 : 정상
서버 머신 자체에서 curl localhost:9000 :8080 -> 도커 컨테이너 : error
외부 머신 telnet 9000 -> 도커 컨테이너 : 9000 / 8080
어라...갑자기 외부에서도 텔넷이 되네요.....
안되었었는데, 희안하네요
어제 ipv6 off 하고 reboot 하고도 안되었는데,.,.ㅡㅡ
다만 역시 접속은 안되니,
도커 내부 컨테이너의 포테이너 / 아파치 앱이 비정상 생성? 되는 듯한 느낌입니다...ㅜㅜ
일단 포트가 정상적으로 열려있는 것으로 보이는데..
curl의 정확한 에러코드를 적어줘보시겠어요?
curl localhost:9000
curl: (56) Recv failure: Connection reset by peer
텔넷하면 일단 연결은 되는 듯 합니다...
telnet localhost 9000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
(스크립트랑 차이가 없는데...)
-----------------------------------------------
➜ cat docker-compose.yml
version: '3'
services:
portainer:
image: portainer/portainer
container_name: portainer
restart: always
ports:
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
-----------------------------------------------
그냥 스크립트로 처음 할 때 안되서 지우고 다시 하니까 Portainer.io 웹 UI가 뜨네요...
docker system prune -fa
아니면 버전을 3.7 정도로 높게 하시면 어떠실지...
컨테이너 이름 보다는 alias가 나을 수도 있구요...
제가 봐도 위에 고수님들 답변들이 말이 된다고 보는데, 왜 안 되는지 잘 모르겠네요.
ufw 설정 같은 것도 다 풀어 보시고... 아니면, 첨부한 이미지처럼 설정 해보세요.
aliases는 도커 네트워크 내부에서 각 컨테이너의 네트워크 별명을 설정한다고 보시면 될 것 같습니다. mdns (avahi) 처럼요 ㅎㅎ
docker-compose 로도 해보았었습니다. 역시 마찬가지 였었구요..ㅜㅜ
ufw 설정 찾아보겠습니다.
이게, 도커를 깔고 무언가 컨테이너를 올리면 외부 접속이 안되는
현상을 추적하다가 portainer 가 제일 깔기 쉬워서
테스트 용으로 사용 하는 것입니다.
mysql 도 컨테이너로 올리면 외부 접속이 안되어서요...ㅜㅜ
조언 감사합니다.