Herramientas de usuario

Herramientas del sitio


wiki2:docker

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:docker [2018/04/11 10:45]
alfred [Fast use]
wiki2:docker [2020/11/07 13:33] (actual)
Línea 6: Línea 6:
  
 <​code>​ <​code>​
-docker run -v /​home/​alfred/​tmp/​data:/​data/​db -p 27017:27017 mongo+docker run --rm -d -v /​home/​alfred/​tmp/​data:/​data/​db ​-v /​tmp:/​tmp ​-p 27017:​27017 ​--name mongo mongo
 </​code>​ </​code>​
  
Línea 23: Línea 23:
 <​code>​ <​code>​
 sudo docker run -p 5432:5432 -v /​home/​alfred/​tmp/​postgresdata:/​var/​lib/​postgresql/​data -e POSTGRES_PASSWORD=mysecretpassword postgres sudo docker run -p 5432:5432 -v /​home/​alfred/​tmp/​postgresdata:/​var/​lib/​postgresql/​data -e POSTGRES_PASSWORD=mysecretpassword postgres
 +
 +docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword postgres:​9.4
 </​code>​ </​code>​
  
Línea 34: Línea 36:
 </​code>​ </​code>​
  
 +==== Creación de un docker basado en lo que ya tienes ====
 +1. Crea un archivo ''​Dockerfile''​ y añade:
 +<​code>​
 +FROM php:​7.0-apache
 +</​code>​
 +2. Haz:
 +<​code>​
 +$ sudo build -t my-php
 +</​code>​
 +3. Ejecuta:
 +<​code>​
 +$ sudo docker run -d -p 8000:80 -v /​home/​alfred/​php/:/​var/​www/​html my-php
 +</​code>​
 ---- ----
  
Línea 42: Línea 57:
  
  
 +Para instalarlo en un server virtual, este ha de ser KVM.
 ===== How to use it ===== ===== How to use it =====
  
Línea 274: Línea 290:
  
 The last part is really important - even though that's the MySQL default port, if we don't tell docker explicitly we want to map it, it will block access through that port (because containers are isolated until you tell them you want access). The last part is really important - even though that's the MySQL default port, if we don't tell docker explicitly we want to map it, it will block access through that port (because containers are isolated until you tell them you want access).
 +
 +=== Php ===
 +
 +Enable MySQL libraries:
 +<​code>​
 +FROM php:​7.0-apache
 +
 +RUN /​usr/​local/​bin/​docker-php-ext-install mysqli
 +RUN /​usr/​local/​bin/​docker-php-ext-install pdo_mysql
 +
 +RUN apt update && apt install mysql-client-5.5 -y
 +</​code>​
 ===== Dockerfile ===== ===== Dockerfile =====
  
Línea 353: Línea 381:
 Whe we run ''​docker compose down''​ we are shutting down the containers. Whe we run ''​docker compose down''​ we are shutting down the containers.
  
 +==== Volumes ====
 +<​code>​
 +docker volume ls
 +docker volume prune
 +</​code>​
 +==== With networks ====
 +<​code>​
 +version: "​3"​
 +services:
  
 +  proxy:
 +    build: ./proxy
 +    networks:
 +      - frontend
 +  app:
 +    build: ./app
 +    networks:
 +      - frontend
 +      - backend
 +  db:
 +    image: postgres
 +    networks:
 +      - backend
 +
 +networks:
 +  frontend:
 +    # Use a custom driver
 +    driver: custom-driver-1
 +  backend:
 +    # Use a custom driver which takes special options
 +    driver: custom-driver-2
 +    driver_opts:​
 +      foo: "​1"​
 +      bar: "​2"​
 +</​code>​
 +===== Docker networks =====
 +List docker networks:
 +<​code>​
 +$ sudo docker network ls
 +</​code>​
 +Create network:
 +<​code>​
 +sudo docker network create mynetwork
 +</​code>​
 +Now you can inspect its details (you can see the assigned ip addresses to the hosts):
 +<​code>​
 +$ docker network inspect mynetwork
 +</​code>​
 +To add a docker container to a network just add the parameter:
 +<​code>​
 +--network mynetwork
 +</​code>​
 +
 +==== Assign ip's ====
 +
 +First you need to create you own docker network:
 +<​code>​
 +docker network create --subnet=172.18.0.0/​16 mynet123
 +</​code>​
 +Then run with ip:
 +<​code>​
 +docker run --net mynet123 --ip 172.18.0.22 -it ubuntu bash
 +</​code>​
 +Additionally:​
 +<​code>​
 +--hostname to specify a hostname
 +--add-host to add more entries to /etc/hosts
 +</​code>​
 ===== Use cases ===== ===== Use cases =====
 ==== Using external code ==== ==== Using external code ====
Línea 513: Línea 608:
 > The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user. If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/​writable by the docker group. > The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user. If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/​writable by the docker group.
  
-Still I did not achieve to run it as my own user, the steps would be: +The steps would be: 
-<​code>​  +<​code>​ 
-$ groupadd docker +sudo groupadd docker 
-gpasswd ​-a alfred ​docker+sudo usermod ​-aG docker ​$USER
 </​code>​ </​code>​
  
 +If it did not work:
 +<​code>​
 +sudo groupadd docker
 +sudo usermod -aG docker $USER
 +newgrp docker
 +docker run hello-world
 +</​code>​
 ==== The Docker service configuration ==== ==== The Docker service configuration ====
 You can control the docker service with: ''​service docker start|stop|restart|status''​. ​ You can control the docker service with: ''​service docker start|stop|restart|status''​. ​
Línea 533: Línea 635:
   * https://​codefresh.io/​blog/​everyday-hacks-docker/​   * https://​codefresh.io/​blog/​everyday-hacks-docker/​
  
 +===== Tips =====
  
 +Install MySQL on setting the password:
 +<​code>​
 +FROM php:​7.0-apache
 +
 +RUN { \
 + echo mysql-server mysql-server/​root_password password mypassword; \
 + echo mysql-server mysql-server/​root_password_again password mypassword; \
 + } | debconf-set-selections
 +
 +RUN apt update && apt install -y mysql-server
 +</​code>​
wiki2/docker.1523443507.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)