도커 컨터이너를 잘 사용하다가 컴퓨터를 껐다가 다시 켜고서 docker start 를 다시 하면 포트가 이미 할당되어 있다(port is already allocated) 면서 에러가 발생하는 경우가 있습니다. 


저의 경우, 도커로 Greenplum Database + MADlib + PL/R + PL/Python 설치되어 있는 gpdb-ds 도커 컨터이너를 실행하려고 하니 아래와 같은 에러 메시지가 떴습니다. 


(추측컨데, docker를 정상적으로 종료하지 않고 그냥 컴퓨터를 막 꺼버린 경우에 이런 에러가 발생하는거 아닌가 싶습니다.)



Last login: Wed Sep 19 21:29:53 on ttys002

ihongdon-ui-MacBook-Pro:~ ihongdon$ docker ps -a

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                      PORTS                   NAMES

a0452a877e8c        hdlee2u/gpdb-analytics   "/usr/sbin/sshd -D"      4 weeks ago         Exited (128) 8 days ago                             gpdb-ds

a041b74fa56f        wordpress                "docker-entrypoint.s…"   9 months ago        Exited (128) 9 months ago   0.0.0.0:32769->80/tcp   wordpress

39aabe32259a        mysql:5.7                "docker-entrypoint.s…"   9 months ago        Exited (0) 9 months ago                             wordpressdb

5019a3411cc0        ubuntu:16.04             "/bin/bash"              9 months ago        Exited (0) 6 weeks ago                              my_ubuntu

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ docker start gpdb-ds


Error response from daemon: driver failed programming external connectivity on endpoint gpdb-ds (d519c381360008f0ac0e8d756e97aeb0538075ee1b7e35862a0eaedf887181f1): Error starting userland proxy: Bind for 0.0.0.0:5432 failed: port is already allocated

 






이번 포스팅에서는 도커를 사용할 때 "포트가 이미 할당되어 있어서 연결에 실패했습니다 (port is already allocated)" 에러가  발생했을 때 대처 방법을 소개하겠습니다. 



(1) 5432 포트가 사용 중인지 여부 확인하기 : sudo lsof -i :5432


port 번호는 docker run 할 때 할당했던 port 번호를 입력해주세요. 저는 5432 로 했었기에 5432 입력했습니다.



ihongdon-ui-MacBook-Pro:~ ihongdon$ sudo lsof -i :5432

Password:

COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME

postgres  93 postgres    4u  IPv6 0x92aed4eef954d8e1      0t0  TCP *:postgresql (LISTEN)

postgres  93 postgres    5u  IPv4 0x92aed4eef9554549      0t0  TCP *:postgresql (LISTEN)

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

 



postgresql 두 개가 5432 port 를 점유하고 있네요. 




(2) 이미 할당된 port 죽이기 : sudo kill -15 93



ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ sudo kill -15 93

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

 


 죽여, 살려 하니깐 좀 말이 과격한데요, ^^; 원치 않게 자리를 점하고 있던 좀비 port를 죽였습니다(kill). 



(1)번에서 했던 방법으로 5432 번호에 할당된 port를 조회해 볼까요? 아무것도 없네요. 



ihongdon-ui-MacBook-Pro:~ ihongdon$ sudo lsof -i :5432

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

 




(3) 도커 컨터이너 시작하기 : docker start container_name



ihongdon-ui-MacBook-Pro:~ ihongdon$ docker start gpdb-ds

gpdb-ds

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ docker ps -a

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                      PORTS                                              NAMES

a0452a877e8c        hdlee2u/gpdb-analytics   "/usr/sbin/sshd -D"      4 weeks ago         Up 6 seconds                0.0.0.0:5432->5432/tcp, 0.0.0.0:28080->28080/tcp   gpdb-ds

a041b74fa56f        wordpress                "docker-entrypoint.s…"   9 months ago        Exited (128) 9 months ago   0.0.0.0:32769->80/tcp                              wordpress

39aabe32259a        mysql:5.7                "docker-entrypoint.s…"   9 months ago        Exited (0) 9 months ago                                                        wordpressdb

5019a3411cc0        ubuntu:16.04             "/bin/bash"              9 months ago        Exited (0) 6 weeks ago                                                         my_ubuntu

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ 

ihongdon-ui-MacBook-Pro:~ ihongdon$ docker exec -it gpdb-ds /bin/bash

[root@mdw /]# 

[root@mdw /]# 

[root@mdw /]# su gpadmin

[gpadmin@mdw /]$ 

[gpadmin@mdw /]$ 

[gpadmin@mdw /]$ gpstart -a

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Starting gpstart with args: -a

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Gathering information and validating the environment...

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Greenplum Binary Version: 'postgres (Greenplum Database) 5.10.2 build commit:b3c02f3acd880e2d676dacea36be015e4a3826d4'

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Greenplum Catalog Version: '301705051'

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[WARNING]:-postmaster.pid file exists on Master, checking if recovery startup required

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Commencing recovery startup checks

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Have lock file /tmp/.s.PGSQL.5432 but no process running on port 5432

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-No Master instance process, entering recovery startup mode

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Clearing Master instance lock files

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Clearing Master instance pid file

20180924:13:03:26:000040 gpstart:mdw:gpadmin-[INFO]:-Starting Master instance in admin mode

20180924:13:03:27:000040 gpstart:mdw:gpadmin-[INFO]:-Obtaining Greenplum Master catalog information

20180924:13:03:27:000040 gpstart:mdw:gpadmin-[INFO]:-Obtaining Segment details from master...

20180924:13:03:27:000040 gpstart:mdw:gpadmin-[INFO]:-Setting new master era

20180924:13:03:27:000040 gpstart:mdw:gpadmin-[INFO]:-Commencing forced instance shutdown

20180924:13:03:29:000040 gpstart:mdw:gpadmin-[INFO]:-Starting Master instance in admin mode

20180924:13:03:30:000040 gpstart:mdw:gpadmin-[INFO]:-Obtaining Greenplum Master catalog information

20180924:13:03:30:000040 gpstart:mdw:gpadmin-[INFO]:-Obtaining Segment details from master...

20180924:13:03:30:000040 gpstart:mdw:gpadmin-[INFO]:-Setting new master era

20180924:13:03:30:000040 gpstart:mdw:gpadmin-[INFO]:-Master Started...

20180924:13:03:30:000040 gpstart:mdw:gpadmin-[INFO]:-Shutting down master

20180924:13:03:31:000040 gpstart:mdw:gpadmin-[INFO]:-Commencing parallel segment instance startup, please wait...

.. 

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-Process results...

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-----------------------------------------------------

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-   Successful segment starts                                            = 2

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-   Failed segment starts                                                = 0

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-   Skipped segment starts (segments are marked down in configuration)   = 0

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-----------------------------------------------------

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-Successfully started 2 of 2 segment instances 

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-----------------------------------------------------

20180924:13:03:33:000040 gpstart:mdw:gpadmin-[INFO]:-Starting Master instance mdw directory /data/master/gpseg-1 

20180924:13:03:34:000040 gpstart:mdw:gpadmin-[INFO]:-Command pg_ctl reports Master mdw instance active

20180924:13:03:34:000040 gpstart:mdw:gpadmin-[INFO]:-No standby master configured.  skipping...

20180924:13:03:34:000040 gpstart:mdw:gpadmin-[INFO]:-Database successfully started

[gpadmin@mdw /]$ 

[gpadmin@mdw /]$  




다시 잘 실행되네요. ^^


많은 도움이 되었기를 바랍니다. 


---------------


도커 컨테이터로 Greenplum Database + MADlib + PL/R + PL/Python 사용환경을 간단하게 구성하고 싶은 분은 http://rfriend.tistory.com/379 포스팅을 참고하세요. 10분만 투자하면 됩니다. 


728x90
반응형
Posted by Rfriend
,