Docker Compose

Apr 21, 2024

Docker Compose

Raspberry Pi OSThanks Ahmed Merabet

Abrir la Terminal--Open Terminal 


Ahora debemos decidir si queremos o no correr docker sin ser root, si tu respuesta es no, saltate este paso, si es afirmativa ingresa el siguiente comando--Now we have to choose run docker like root or non-root-user, if you want run like root jump this step, if you want run like non-root-user introduce this command:

Vemos un mensaje sobre dependencias que nos faltan, copiamos el mensaje en la Terminal  para que se instale--We see that need some dependencies, so copy the message and paste on Terminal.

Volvemos a ejecutar--Run again:

Vemos un mensaje que nos advierte soobre agregar 2 variables al bashrc--Then we see another message about add 2 variables to bashrc:

Ingresa las 2 líneas al final del archivo--Add this 2 lines to the end of file: 

Guardamos, cerramos y reiniciamos la Raspberry Pi--Close and save with Ctrl+x, Y, Enter then reboot the Raspberry Pi:

Agregamos nuestro usuario al grupo docker--Add our user to docker's group(Optional):

Tras reiniciar abrimos la Terminal y vemos la versión--After reboot open Terminal and check docker compose version:

Docker Compose Version v2.21.0. 


Probamos su funcionamiento con un ejemplo--Test with an example:


Esta es la forma normal de correr docker--This is the docker way:


Esta es la forma en que hacemos correr nuestro contenedor con Docker compose--This is the Docker Compose way to run a container:

Abrimos otra Terminal sin cerrar la anterior--Open another Terminal without close the other:


Ingresamos--Type:

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.

Lo ejecutamos--Run:

Notemos que a diferencia del video de Network Chuck no hemos instalado docker.io ni docker-compose desde el repositorio, es por esto que al ejecutar ingresamos docker compose en lugar de docker-compose.

Notice that at difference of Network Chuck video, we don't install docker.io and docker-compose from repo, is for this that when run it we use docker compose instead of docker-compose.

Abrimos el navegador e introducimos--Open browser and type:

Te preguntarás cuál es la diferencia?, en este ejemplo se ve más sencillo solo utilizar docker run, pero que si queremos correr 314 contenedores?. Bueno, necesitariamos ejecutar 314 veces docker run, pero con docker compose solo editamos un archivo (docker-compose.yaml) con las configuraciones de los 314 contenedores y luego solo ejecutamos una linea:

Solo una, para correr 314 contenedores(314 es pi * 100 (^- *) ).Esto lo podemos observar en el siguiente ejemplo del video de Network Chuck.

Which is the diferencey you ask, in this example seems to be more easy just use docker run, but what if you want to run 314 containers? Well you need to execute 314 times docker run. But with docker compose you build one file (docker-compose.yaml) with the 314 containers setup then just run it all with:

Just one line to run 314 containers(314 is pi by 100 (^- *) ). This we can see in the next example of Network Chuck Video.

Wordpress-MariaDB-PhpMyAdmin-Apache:

Raspberry pi Os 32bit & 64bit

Raspberry Pi OS 32 bit

Abre la--Open Terminal:

Escribimos--Type:

En ports, si lo tenemos ocupado cambiamos por otro--If we have ports busy, change by another

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.

Lo ejecutamos--Run:

Raspberry Pi OS 64 bit

Abre la--Open Terminal:

Clonaremos la repo awsome-compose--We will clone the repo awesome-compose.

Abrimos el navegador--Open the browser:

Detener y borrar todo si lo deseamos con--Stop and delete all if you wish:

Wordpress Dashboard

Portainer

Abre la--Open Terminal:

Escribimos--Type:

En ports, si lo tenemos ocupado cambiamos por otro--If we have ports busy, change by another

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.

Lo ejecutamos--Run:

PHP application with Apache2

Abre la--Open Terminal:

Escribimos--Type:

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.


Hacemos el  archivo de la web--Make an index web file:

Escribimos--Type:

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.


Ahora creamos el archivo yaml--Now the yaml file:

Escribimos--Type:

En ports, si lo tenemos ocupado cambiamos por otro--If we have ports busy, change by another

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.

Lo ejecutamos--Run:

O clonando desde Awesome-Compose Repo--Or Clone Awesome-Compose Repo

Abre la--Open Terminal:

Clonaremos la repo awsome-compose--We will clone the repo awesome-compose.

Abrimos el navegador--Open the browser:

MariaDB & PhpMyAdmin

Raspberry Pi OS 64bit

Abre la--Open Terminal:

Escribimos--Type:

Guardar y cerrar--Close and save with Ctrl+x, Y, Enter.

Lo ejecutamos--Run:

Abrimos el navegador e iniciamos sesion--Open the browser and login:

Server empty
Running

Angular

Raspberry Pi OS 64bit

Abre la--Open Terminal:

Clonaremos la repo awsome-compose--We will clone the repo awesome-compose.

Abrimos el navegador--Open the browser:

http://localhost:4200

ASP.net & Microsoft My SQL Server app

Abre la--Open Terminal:

Clonaremos la repo awsome-compose--We will clone the repo awesome-compose.

Abrimos el navegador--Open the browser:

Detenemos la app y borramos todo con--Stop and delete the app with:

http://localhost

Comandos Básicos--Basic Commands:

Correr Docker--Run Docker:

Detener Docker--Stop Docker:

Eliminar volumenes creados--Delete volumes:

Eliminar Huerfanos-- Remove Orphans:

Listar proyectos Docker Compose encendidos--List run projects:


Usage:  docker compose [OPTIONS] COMMAND


Docker Compose


Options:

      --ansi string                Control when to print ANSI control characters ("never"|"always"|"auto")

                                   (default "auto")

      --compatibility              Run compose in backward compatibility mode

      --env-file string            Specify an alternate environment file.

  -f, --file stringArray           Compose configuration files

      --profile stringArray        Specify a profile to enable

      --project-directory string   Specify an alternate working directory

                                   (default: the path of the, first specified, Compose file)

  -p, --project-name string        Project name


Commands:

  build       Build or rebuild services

  convert     Converts the compose file to platform's canonical format

  cp          Copy files/folders between a service container and the local filesystem

  create      Creates containers for a service.

  down        Stop and remove containers, networks

  events      Receive real time events from containers.

  exec        Execute a command in a running container.

  images      List images used by the created containers

  kill        Force stop service containers.

  logs        View output from containers

  ls          List running compose projects

  pause       Pause services

  port        Print the public port for a port binding.

  ps          List containers

  pull        Pull service images

  push        Push service images

  restart     Restart service containers

  rm          Removes stopped service containers

  run         Run a one-off command on a service.

  start       Start services

  stop        Stop services

  top         Display the running processes

  unpause     Unpause services

  up          Create and start containers

  version     Show the Docker Compose version information

Home Assistant

Abre la--Open Terminal:

Escribimos--Type:

En ports, si lo tenemos ocupado cambiamos por otro--If we have ports busy, change by another

Guardar y cerrar--Close and save with Ctrl+S, Ctrl+x.

Lo ejecutamos--Run:

Si usamos root para docker compose:

Accedemos al dashboard desde el navegador, reemplazamos <host> con nuestra IP:

Ejemplo:

Otra manera de instalación:

docker run -d \

  --name homeassistant \

  --privileged \

  --restart=unless-stopped \

  -e TZ=MY_TIME_ZONE \

  -v /PATH_TO_YOUR_CONFIG:/config \

  -v /run/dbus:/run/dbus:ro \

  --network=host \

  ghcr.io/home-assistant/home-assistant:stable

MY_TIME_ZONE: 

Debe ser reemplazado por la zona horaria de tu residencia, puedes averiguar la tuya aquí, en mi caso en buenos aires quedando:

/PATH_TO_YOUR_CONFIG

Debe ser reemplazado por el directorio que creamos:

docker run -d \

  --name homeassistant \

  --privileged \

  --restart=unless-stopped \

  -e TZ=America/Argentina/Buenos_Aires \

  -v /HASS:/config \

  -v /run/dbus:/run/dbus:ro \

  --network=host \

  ghcr.io/home-assistant/home-assistant:stable

Lo ejecutamos--Run:

Si usamos root para docker compose:

Accedemos al dashboard desde el navegador, reemplazamos <host> con nuestra IP:

Ejemplo:

Docker Compose Reference:

Common Reference:

Run:

Start:

Stop:

Up:

Down: