|
| 1 | +# Install Docker Engine on Ubuntu |
| 2 | + |
| 3 | +## Set up the repository |
| 4 | +- Update the apt package index and install packages to allow apt to use a repository over HTTPS: |
| 5 | + ```shell |
| 6 | + sudo apt-get update |
| 7 | + sudo apt-get install ca-certificates curl gnupg |
| 8 | + ``` |
| 9 | +- Add Docker’s official GPG key: |
| 10 | + ```shell |
| 11 | + sudo install -m 0755 -d /etc/apt/keyrings |
| 12 | + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg |
| 13 | + sudo chmod a+r /etc/apt/keyrings/docker.gpg |
| 14 | + ``` |
| 15 | +- Use the following command to set up the repository: |
| 16 | + ```shell |
| 17 | + echo \ |
| 18 | + "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ |
| 19 | + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ |
| 20 | + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
| 21 | + ``` |
| 22 | +## Install Docker Engine |
| 23 | +- Update the apt package index: |
| 24 | + ```shell |
| 25 | + sudo apt-get update |
| 26 | + ``` |
| 27 | +- Install Docker Engine: |
| 28 | + ```shell |
| 29 | + sudo apt install docker-ce |
| 30 | + ``` |
| 31 | +- Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running: |
| 32 | + ```shell |
| 33 | + sudo systemctl status docker |
| 34 | + ``` |
| 35 | +## Executing the Docker Command Without Sudo |
| 36 | +- If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group: |
| 37 | + ```shell |
| 38 | + sudo usermod -aG docker ${USER} |
| 39 | + ``` |
| 40 | +- To apply the new group membership, log out of the server and back in, or type the following: |
| 41 | + ```shell |
| 42 | + su - ${USER} |
| 43 | + ``` |
| 44 | + You will be prompted to enter your user’s password to continue. |
| 45 | +- Confirm that your user is now added to the docker group by typing: |
| 46 | + ```shell |
| 47 | + id -nG |
| 48 | + ``` |
| 49 | +## Installing Docker Compose |
| 50 | +- Check the [current release](https://github.com/docker/compose/releases) and if necessary, update it in the command below: |
| 51 | + ```shell |
| 52 | + sudo curl -L https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose |
| 53 | + ``` |
| 54 | +- Next set the permissions: |
| 55 | + ```shell |
| 56 | + sudo chmod +x /usr/local/bin/docker-compose |
| 57 | + ``` |
| 58 | +- Then you’ll verify that the installation was successful by checking the version: |
| 59 | + ```shell |
| 60 | + docker-compose --version |
| 61 | + ``` |
| 62 | + |
| 63 | +## Reference |
| 64 | +- [Docker](https://docs.docker.com/engine/install/ubuntu/) |
0 commit comments