How to upgrade docker server version?

I am learning docker-compose according to this.

After I running docker-compose up, it says

/tmp/_MEIepUvmP/docker/api/client.py:163: UserWarning: The minimum API version supported is 1.21, but you are using version 1.18. It is recommended you either upgrade Docker Engine or use an older version of Docker SDK for Python.
Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 71, in main
  File "compose/cli/main.py", line 124, in perform_command
  File "compose/cli/main.py", line 1001, in up
  File "compose/cli/main.py", line 997, in up
  File "compose/project.py", line 451, in up
  File "compose/project.py", line 508, in initialize
  File "compose/network.py", line 262, in initialize
  File "compose/network.py", line 63, in ensure
  File "compose/network.py", line 96, in inspect
  File "site-packages/docker/utils/decorators.py", line 31, in wrapper
docker.errors.InvalidVersion: inspect_network is not available for version < 1.21
Failed to execute script docker-compose

My docker version is:

Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.2.1
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.2.1
Git commit (server): 7c8fca2
OS/Arch (server): linux/amd64

Then, I try export COMPOSE_API_VERSION=1.21, it says

ERROR: client and server don't have same version (client : 1.21, server: 1.18)

I guess this problem may be solved if I upgrade the server version to 1.21, but I don't know how to do this, any idea ?


Solution 1:

You need to upgrade your docker installation. The docker homepage describes how to install docker-ce.

Follow these steps to the letter: remove current docker, add docker-ce repository, add pgp key then install docker-ce

$ sudo apt-get remove --purge docker docker-engine docker.io
$ sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
    | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ sudo apt-get update
$ sudo apt-get install docker-ce

Update: Changed gpg key handling from apt-key add to the new, recommended storing of the key in /usr/share/keyrings/