Skip to content

Instantly share code, notes, and snippets.

@tonybolanyo
Last active November 6, 2021 01:26
Show Gist options
  • Save tonybolanyo/d666cb2fb82299341b0fb1d92e89c9f7 to your computer and use it in GitHub Desktop.
Save tonybolanyo/d666cb2fb82299341b0fb1d92e89c9f7 to your computer and use it in GitHub Desktop.
Instalar docker y docker-compose en ubuntu 18.04
# Instalar docker
First, update your existing list of packages:
```
sudo apt update
```
Next, install a few prerequisite packages which let apt use packages over HTTPS:
```
sudo apt install apt-transport-https ca-certificates curl software-properties-common
```
Then add the GPG key for the official Docker repository to your system:
```
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```
Add the Docker repository to APT sources:
```
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
```
Next, update the package database with the Docker packages from the newly added repo:
```
sudo apt update
```
Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
```
apt-cache policy docker-ce
```
You’ll see output like this, although the version number for Docker may be different:
```
Output of apt-cache policy docker-ce
docker-ce:
Installed: (none)
Candidate: 18.03.1~ce~3-0~ubuntu
Version table:
18.03.1~ce~3-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 18.04 (bionic).
```
Finally, install Docker:
```
sudo apt install docker-ce
```
Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
```
sudo systemctl status docker
```
The output should be similar to the following, showing that the service is active and running:
Output
```
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-07-05 15:08:39 UTC; 2min 55s ago
Docs: https://docs.docker.com
Main PID: 10096 (dockerd)
Tasks: 16
CGroup: /system.slice/docker.service
├─10096 /usr/bin/dockerd -H fd://
└─10113 docker-containerd --config /var/run/docker/containerd/containerd.toml
```
Installing Docker now gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client. We’ll explore how to use the docker command later in this tutorial.
## Step 2 — Executing the Docker Command Without Sudo (Optional)
By default, the docker command can only be run the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you’ll get an output like this:
Output
```
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
```
If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:
```
sudo usermod -aG docker ${USER}
```
To apply the new group membership, log out of the server and back in, or type the following:
```
su - ${USER}
```
You will be prompted to enter your user’s password to continue.
Confirm that your user is now added to the docker group by typing:
```
id -nG
```
Output
```
sammy sudo docker
```
If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:
```
sudo usermod -aG docker username
```
# Instalar docker compose
Si bien se puede instalar Docker Compose desde los repositorios oficiales de Ubuntu, la versión está considerablemente atrasada respecto de la más reciente. Por lo tanto, instalaremos Docker Compose desde el repositorio de GitHub. El comando que se muestra a continuación difiere ligeramente respecto del que encontrará en la página Versiones. Al usar el indicador -o para especificar primero el archivo de salida en lugar de redirigirla, esta sintaxis evita que se produzca un error de denegación de permiso al usar sudo.
Revisaremos la versión actual y, si es necesario, la actualizaremos en el comando que se muestra a continuación:
```
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
```
Luego, configuraremos los permisos:
```
sudo chmod +x /usr/local/bin/docker-compose
```
A continuación, comprobaremos que la instalación se haya realizado de forma correcta revisando la versión:
```
docker-compose --version
```
Con esto se imprimirá la versión que instalamos:
Output
```
docker-compose version 1.21.2, build a133471
```
Ahora que instalamos Docker Compose, estamos listos para ejecutar un ejemplo “Hello World”.
# Referencias
- Instalar docker: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04
- Instalar docker-compose: https://www.digitalocean.com/community/tutorials/como-instalar-docker-compose-en-ubuntu-18-04-es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment