made a makefile

+ added names of images and container in compose
+ have a functionnal nginx dockerfile
This commit is contained in:
hugo gogo
2022-08-30 11:23:38 +02:00
parent cbe0edc1ce
commit 428dc1ecee
4 changed files with 136 additions and 3 deletions

View File

@@ -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`