2

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  
Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73

1 Answers1

3

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.

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
  • 1
    So why wouldn’t `'22'` (no period) work? In the linked documentation it shows `'3000'` This matches the rule “Specify just the container port (*an ephemeral host port is chosen for the host port*).” – user2864740 Jan 10 '22 at 10:30
  • good comment, I forgot to explicitly mention that I am using this with `nerdctl` command, not with `docker` . – Akshay Vijay Jain Jan 10 '22 at 10:32