unsupported port number: 0

997 views Asked by At

If we specify single port in dockerfile or docker-compose file like below

  sshd:
    build: ./backend/mock/sshd
    volumes:
      - ./docker/sftp_upload_dir:/root/upload_dir
    ports:
      - '22'. #<----------

and use the docker-compose file with nerdctl using command

nerdctl compose up

then nerdctl command will exit with following error

FATA[0000] unsupported port number: 0  
1

There are 1 answers

2
Akshay Vijay Jain On

As per docker documentation https://docs.docker.com/compose/compose-file/compose-file-v3/#ports

There are three options:

Specify both ports (HOST:CONTAINER)
Specify just the container port (an ephemeral host port is chosen for the host port).

Thus 0 is chosen as the host port which creates error, so solution is to explicitly specify host port as below

  sshd:
    build: ./backend/mock/sshd
    volumes:
      - ./docker/sftp_upload_dir:/root/upload_dir
    ports:
      - '22:22' #<<<<---------

Note that I have explicitly added 22: before 22 in the last line to make it work with nerdctl. It works by default with docker-compose up.