Can’t forward mongodb port on docker

I want to create node-mongodb app under the container. Problem is that port 27017 is already used on the main machine localhost.

I changed the mongo container port to 5000 but it is not working.

docker-compose.yml

version: '3'
services:
  mongo:
    container_name: mongo
    image: mongo
    volumes:
      - ./data:/data/db
    ports:
      - 5000:27017
  gecar_app:
    build: 
      context: . 
      dockerfile: Dockerfile.gecars
    restart: always
    tty: true
    ports:
      - 3000:3000
    depends_on:
      - mongo
    command: bash -c "/usr/app/wait-for-it.sh --timeout=20 mongo:5000 && /usr/app/initAndStartService.sh"

/usr/app/wait-for-it.sh from https://github.com/vishnubob/wait-for-it it not run initAndStartService.sh until port is ready.

compose output:

...
Successfully tagged gecars2_gecar_app:latest
Recreating mongo ... done
Recreating gecars2_gecar_app_1 ... done
Attaching to mongo, gecars2_gecar_app_1
gecar_app_1  | wait-for-it.sh: waiting 20 seconds for mongo:5000
gecar_app_1  | /usr/app/wait-for-it.sh: line 29: els: command not found
mongo        | 2019-12-31T08:07:13.134+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
mongo        | 2019-12-31T08:07:13.137+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=3744f5e05266
mongo        | 2019-12-31T08:07:13.137+0000 I  CONTROL  [initandlisten] db version v4.2.1
mongo        | 2019-12-31T08:07:13.137+0000 I  CONTROL  [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
mongo        | 2019-12-31T08:07:13.137+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
gecar_app_1  | wait-for-it.sh: waiting for mongo:5000 without a timeout
mongo        | 2019-12-31T08:07:13.137+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
mongo        | 2019-12-31T08:07:13.138+0000 I  CONTROL  [initandlisten] modules: none
mongo        | 2019-12-31T08:07:13.138+0000 I  CONTROL  [initandlisten] build environment:
mongo        | 2019-12-31T08:07:13.138+0000 I  CONTROL  [initandlisten]     distmod: ubuntu1804
mongo        | 2019-12-31T08:07:13.138+0000 I  CONTROL  [initandlisten]     distarch: x86_64
mongo        | 2019-12-31T08:07:13.138+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
mongo        | 2019-12-31T08:07:13.138+0000 I  CONTROL  [initandlisten] options: { net: { bindIp: "*" } }
mongo        | 2019-12-31T08:07:13.145+0000 I  STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongo        | 2019-12-31T08:07:13.151+0000 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=487M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
mongo        | 2019-12-31T08:07:20.241+0000 I  STORAGE  [initandlisten] WiredTiger message [1577779640:241618][1:0x7f091088db00], txn-recover: Recovering log 2 through 3
mongo        | 2019-12-31T08:07:20.528+0000 I  STORAGE  [initandlisten] WiredTiger message [1577779640:528306][1:0x7f091088db00], txn-recover: Recovering log 3 through 3
mongo        | 2019-12-31T08:07:20.792+0000 I  STORAGE  [initandlisten] WiredTiger message [1577779640:792164][1:0x7f091088db00], txn-recover: Main recovery loop: starting at 2/5120 to 3/256
mongo        | 2019-12-31T08:07:21.143+0000 I  STORAGE  [initandlisten] WiredTiger message [1577779641:142990][1:0x7f091088db00], txn-recover: Recovering log 2 through 3
mongo        | 2019-12-31T08:07:21.424+0000 I  STORAGE  [initandlisten] WiredTiger message [1577779641:424259][1:0x7f091088db00], txn-recover: Recovering log 3 through 3
mongo        | 2019-12-31T08:07:21.461+0000 I  STORAGE  [initandlisten] WiredTiger message [1577779641:461069][1:0x7f091088db00], txn-recover: Set global recovery timestamp: (0,0)
mongo        | 2019-12-31T08:07:21.488+0000 I  RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
mongo        | 2019-12-31T08:07:21.500+0000 I  STORAGE  [initandlisten] Timestamp monitor starting
mongo        | 2019-12-31T08:07:21.503+0000 I  CONTROL  [initandlisten]
mongo        | 2019-12-31T08:07:21.503+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
mongo        | 2019-12-31T08:07:21.503+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
mongo        | 2019-12-31T08:07:21.503+0000 I  CONTROL  [initandlisten]
mongo        | 2019-12-31T08:07:21.514+0000 I  SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
mongo        | 2019-12-31T08:07:21.521+0000 I  STORAGE  [initandlisten] Flow Control is enabled on this deployment.
mongo        | 2019-12-31T08:07:21.522+0000 I  SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
mongo        | 2019-12-31T08:07:21.523+0000 I  SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
mongo        | 2019-12-31T08:07:21.533+0000 I  SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
mongo        | 2019-12-31T08:07:21.534+0000 I  FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongo        | 2019-12-31T08:07:21.539+0000 I  SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
mongo        | 2019-12-31T08:07:21.539+0000 I  SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
mongo        | 2019-12-31T08:07:21.539+0000 I  NETWORK  [initandlisten] Listening on /tmp/mongodb-27017.sock
mongo        | 2019-12-31T08:07:21.539+0000 I  NETWORK  [initandlisten] Listening on 0.0.0.0
mongo        | 2019-12-31T08:07:21.540+0000 I  NETWORK  [initandlisten] waiting for connections on port 27017
mongo        | 2019-12-31T08:07:22.010+0000 I  SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecar_app_1  | wait-for-it.sh: waiting 20 seconds for mongo:5000
gecar_app_1  | /usr/app/wait-for-it.sh: line 29: els: command not found
gecar_app_1  | wait-for-it.sh: waiting for mongo:5000 without a timeout
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124
gecar_app_1  | wait-for-it.sh: timeout occurred after waiting 20 seconds for mongo:5000
gecars2_gecar_app_1 exited with code 124

Source: StackOverflow