img

nginx89

DOSSIERS locaux : html / ngshare Image docker : [nginx - mc - vim]

Dockerfile

# image de base : serveur http nginx
FROM nginx:latest

COPY ./html/index.html /usr/share/nginx/html

# personalisation shell bash root
COPY ./bashrc /root/.bashrc

# install mc (Midnight Commander), vim
RUN apt-get update && apt-get install -y --no-install-recommends xz-utils man-db mc mcedit vim apt-utils

# nettoyage apt
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
EXPOSE 443

# volumes partagés
VOLUME ["/home/ngshare"]
VOLUME ["/usr/share/nginx"]

# check si le serveur répond
HEALTHCHECK --interval=45s --timeout=5s CMD curl -f http://localhost || exit 1

docker-compose.yml

services:
  nginxdev:
    image: nginx_d
    container_name: nginx89
    ports:
      - "8089:80"
    volumes:
      - ./ngshare:/home/share
      - ./html:/usr/share/nginx/html
volumes:
  ngshare:
  html:
        

Commandes pour build, lancement du conteneur et accès via une console :


# docker build --no-cache -t nginx_d .
# docker run -d --name nginx_d -p 8089:80 -v $(pwd)/ngshare:/home/ngshare -v $(pwd)/html:/usr/share/nginx/html nginx_d
# docker exec -it nginx_d bash
                    

Commande pour docker-compose

Si pas déjà fait :# docker build --no-cache -t nginx_d .
Lancement du conteneur :# docker-compose up -d
http://localhost:8089

Le dossier html (situé dans le répertoire courant),
est le dossier de travail pour les pages servies par nginx.