Cannot npm publish a package: DEPTH_ZERO_SELF_SIGNED_CERT failed, reason: self signed certificate

I installed GitLab locally on Ubuntu 20.04 using docker.
Here is my docker-compose.yml:

version: '3.7'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab.my.domain'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.my.domain'
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'

To access the domain, I added it to the /etc/hosts.

Now I can connect to the gitlab using browser and everythings goes fine.

The problem is that I cannot publish my NPM package.

I did configure project-specific auth and npm using corresponding docs:

$ npm config set @foo:registry https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/npm/
$ npm config set -- '//gitlab.example.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken' "<your_token>"

but now when I publish the package I get the following error:

$ npm publish
...
 npm ERR! request to https://gitlab.my.doman/api/v4/projects/2/packages/npm/@scope%2fmy-package failed, reason: self signed certificate

I also tried to use plain HTTP url for the external_host variable, but it lead to another error:

npm ERR! network request to https://gitlab.my.domain/api/v4/projects/2/packages/npm/@scope%2fmy-package failed, reason: Client network socket disconnected before secure TLS connection was established

Any ideas what’s wrong?