made a makefile
+ added names of images and container in compose + have a functionnal nginx dockerfile
This commit is contained in:
98
Makefile
Normal file
98
Makefile
Normal file
@@ -0,0 +1,98 @@
|
||||
|
||||
GRAY = "\e[0;30m"
|
||||
RED = "\e[0;31m"
|
||||
GREEN = "\e[0;32m"
|
||||
YELLOW = "\e[0;33m"
|
||||
BLUE = "\e[0;34m"
|
||||
PURPLE = "\e[0;35m"
|
||||
CYAN = "\e[0;36m"
|
||||
WHITE = "\e[0;37m"
|
||||
|
||||
B_GRAY = "\e[1;30m"
|
||||
B_RED = "\e[1;31m"
|
||||
B_GREEN = "\e[1;32m"
|
||||
B_YELLOW = "\e[1;33m"
|
||||
B_BLUE = "\e[1;34m"
|
||||
B_PURPLE = "\e[1;35m"
|
||||
B_CYAN = "\e[1;36m"
|
||||
B_WHITE = "\e[1;37m"
|
||||
|
||||
RESET = "\e[0m"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
COMPOSE = ./srcs/docker-compose.yml
|
||||
|
||||
IMAGES = test \
|
||||
# nginx
|
||||
|
||||
HOME_D = $(shell echo $(HOME))
|
||||
|
||||
VOLUMES_D = $(VOLUMES:%=$(HOME_D)/%)
|
||||
VOLUMES = v_wp_site \
|
||||
v_wp_db
|
||||
|
||||
CONTAINERS = $(IMAGES:%=my%)
|
||||
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
all: build $(VOLUMES_D) up
|
||||
|
||||
$(VOLUMES_D):
|
||||
mkdir -p $(VOLUMES_D)
|
||||
|
||||
build:
|
||||
sudo docker-compose -f $(COMPOSE) build
|
||||
|
||||
up: $(VOLUMES_D)
|
||||
sudo docker-compose -f $(COMPOSE) up
|
||||
|
||||
# list images, containers, volumes
|
||||
list:
|
||||
@echo $(B_YELLOW)"\nimages:"$(RESET)
|
||||
@sudo docker images -a
|
||||
@echo $(B_YELLOW)"\ncontainers:"$(RESET)
|
||||
@sudo docker ps -a
|
||||
@echo $(B_YELLOW)"\nvolumes:"$(RESET)
|
||||
@sudo docker volume ls
|
||||
@echo ""
|
||||
|
||||
# remove project images
|
||||
rm-images:
|
||||
sudo docker image rm -f $(IMAGES)
|
||||
|
||||
# stop project containers
|
||||
stop:
|
||||
- sudo docker stop $(CONTAINERS)
|
||||
|
||||
# remove project containers
|
||||
rm-containers: stop
|
||||
- sudo docker rm $(CONTAINERS)
|
||||
|
||||
# remove project images and containers
|
||||
clean: rm-images stop rm-containers
|
||||
|
||||
# remove project volumes
|
||||
rm-volumes:
|
||||
- sudo docker volume rm -f $(VOLUMES)
|
||||
/bin/rm -rf $(VOLUMES_D)
|
||||
|
||||
# remove project
|
||||
fclean: clean rm-volumes
|
||||
|
||||
# remove all dockers
|
||||
ffclean:
|
||||
sudo docker stop $(sudo docker ps -q)
|
||||
sudo docker system prune -af --volumes
|
||||
/bin/rm -rf $(VOLUMES_D)
|
||||
|
||||
re: fclean all
|
||||
|
||||
rre: ffclean all
|
||||
|
||||
.PHONY : all build up $(VOLUMES_D) list rm-images stop rm-containers clean rm-volumes fclean ffclean re rre
|
||||
|
||||
33
README.md
33
README.md
@@ -15,6 +15,20 @@ This README would normally document whatever steps are necessary to get your app
|
||||
- `sudo netstat -tulpn` to print network connections and see if nginx is running
|
||||
- or : `ps -ax | grep nginx`
|
||||
- `sudo nginx -s quit` to stop it
|
||||
- `sudo docker system prune -af --volumes` -> `-a` also unused images, `-f` without prompt for confirmation
|
||||
- remove stopped containers
|
||||
- remove unused networks
|
||||
- remove unused images
|
||||
- remove build cache
|
||||
- `sudo docker ps -q` all runnings containers
|
||||
- `sudo docker stop $(sudo docker ps -q)` stop all runnings containers
|
||||
**remove project images** rm-images sudo docker image rm -f <name> <name> ...
|
||||
**stop project containers** stop sudo docker stop <name> <name> ...
|
||||
**remove project containers** rm-containers sudo docker rm <name> <name> ...
|
||||
**remove project images and containers** clean rm-images stop rm-containers
|
||||
**remove project volumes** rm-volumes sudo docker volume rm -f <name> <name> ...
|
||||
**remove project** fclean clean rm-volumes
|
||||
**remove all dockers** ffclean sudo docker stop $(sudo docker ps -q); sudo docker system prune -af --volumes
|
||||
|
||||
---
|
||||
## Dockerfile basics
|
||||
@@ -28,12 +42,25 @@ This README would normally document whatever steps are necessary to get your app
|
||||
|
||||
- [download alpine linux](https://alpinelinux.org/downloads/)
|
||||
- [dockerhub alpine image](https://hub.docker.com/_/alpine)
|
||||
- [docker starter guide](https://docs.docker.com/get-started/)
|
||||
- [docker glossaire](https://docs.docker.com/glossary/)
|
||||
- [Dockerfile syntaxe](https://docs.docker.com/engine/reference/builder/)
|
||||
- [determine the parent image](https://forums.docker.com/t/determine-the-parent-image/48611)
|
||||
- [docker image from scratch](https://codeburst.io/docker-from-scratch-2a84552470c8)
|
||||
- [build context and image context](https://stackoverflow.com/questions/55108649/what-is-app-working-directory-for-a-dockerfile/55109065#55109065)
|
||||
- [nginx begginer guide](https://hub.docker.com/_/nginx/)
|
||||
|
||||
#### docker pid 1
|
||||
|
||||
- nginx by default will create some child process (a master and some workers), then it quits (doc ?)
|
||||
- when the first process of a docker container exit, the container exit (doc ?)
|
||||
- so we must tell nginx to not go background : "-g 'daemon off'"
|
||||
- [pid1 docker problem](https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/)
|
||||
- [official nginx docker image](https://hub.docker.com/_/nginx/)
|
||||
- "If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!"
|
||||
- [SO discussion on "-g 'daemon off'"](https://stackoverflow.com/questions/18861300/how-to-run-nginx-within-a-docker-container-without-halting)
|
||||
- "When PID 1 exits, the container will exit" (where is says in the doc ?)
|
||||
- ["By design, containers started in detached mode exit when the root process used to run the container exits"](https://docs.docker.com/engine/reference/run/#detached--d)
|
||||
|
||||
#### install and use docker and compose
|
||||
|
||||
@@ -64,9 +91,11 @@ This README would normally document whatever steps are necessary to get your app
|
||||
**build and run a docker image**
|
||||
- be in directory with a Dockerfile
|
||||
- `sudo docker build --tag <name> .`
|
||||
- `sudo docker images` to list images
|
||||
- `sudo docker run <name>`
|
||||
- `sudo docker image rm -f <number-id>`
|
||||
- `sudo docker images` to list docker images
|
||||
- `sudo docker image rm <number>`
|
||||
- `sudo docker ps` to list docker processes
|
||||
- `sudo docker ps rm <name>`
|
||||
**execute a docker-compose file**
|
||||
- be in directory with a docker-compose.yml file
|
||||
- `sudo docker-compose up`
|
||||
|
||||
@@ -12,3 +12,9 @@ services:
|
||||
build:
|
||||
context: ./requirements/test
|
||||
dockerfile: Dockerfile
|
||||
image: test
|
||||
container_name: mytest
|
||||
# test:
|
||||
# build:
|
||||
# context: ./requirements/test
|
||||
# dockerfile: Dockerfile
|
||||
|
||||
@@ -7,5 +7,5 @@ COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/
|
||||
COPY ./conf/index.html /data/www/
|
||||
COPY ./conf/salade.jpeg /data/images/
|
||||
|
||||
CMD [ "nginx" ]
|
||||
CMD [ "nginx", "-g", "daemon off;" ]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user