Apt-key deprecated error

When doing this:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Error looks like this:

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

This works:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key --keyring /etc/apt/trusted.gpg.d/docker-apt-key.gpg add