FAQ Docker compose

24/03/20 danny

Documentation


Installation

# Installation docker compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

# Test de l'installation
docker-compose --version

# Désinstallation
sudo rm /usr/local/bin/docker-compose

Commandes

# Crée une image à partir du fichier yml
docker-compose build

# Crée une image à partir du yml et execute le container correspondant
docker-compose up -d


# Liste des commandes
docker-compose build
docker-compose images
docker-compose logs
docker-compose ps
docker-compose down
docker-compose stop
docker-compose start
docker-compose restart
docker-compose rm -f

Nginx

Installation de nginx via docker.

Un répertoire proxy contenant

  • Dockerfile
  • index.html
  • nginx.conf

Un fichier docker-compose.yml

/proxy/Dockerfile
FROM nginx:1.17.9

COPY nginx.conf /etc/nginx/nginx.conf
COPY index.html /usr/share/nginx/html
/proxy/index.html
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no">
  <title>titre de notre page</title>
</head>

<body>
  Page index.html via nginx
</body>

</html>
/proxy/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

    server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /usr/share/nginx/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
            try_files $uri /index.html;
        }
    }
}
docker-compose.yml
version: "3"
services:

  proxy-service:
    build: ./proxy
    image : proxy-image
    container_name: proxy-container
    ports:
      - "80:80"
    restart: always
    networks:
      - frontend

networks:
  frontend:
# Création de l'image
docker-compose build

# Création et éxécution du container
docker-compose up -d

# Tester
http://localhost/


name12

FROM node:13.10.1 as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build

FROM nginx:1.17.9
COPY --from=node /app/dist/angular-starter  /usr/share/nginx/html