428dc1ecee411fea0bd3d955b562d75e2ad8de0f
+ added names of images and container in compose + have a functionnal nginx dockerfile
inception
This README would normally document whatever steps are necessary to get your application up and running.
questions
- ? what means mounted in "a file or directory on the host machine is mounted into a container" ?
- ? why the volumes cannot be modify outside docker ?
nginx basics
sudo netstat -tulpnto print network connections and see if nginx is running- or :
ps -ax | grep nginx sudo nginx -s quitto stop itsudo docker system prune -af --volumes->-aalso unused images,-fwithout prompt for confirmation- remove stopped containers
- remove unused networks
- remove unused images
- remove build cache
sudo docker ps -qall runnings containerssudo docker stop $(sudo docker ps -q)stop all runnings containers remove project images rm-images sudo docker image rm -f ... stop project containers stop sudo docker stop ... remove project containers rm-containers sudo docker rm ... remove project images and containers clean rm-images stop rm-containers remove project volumes rm-volumes sudo docker volume rm -f ... 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
- the container posess its own filesystem
- we need to copy the files it uses inside this filesystem
- we can do that with COPY
ressources
- download alpine linux
- dockerhub alpine image
- docker starter guide
- docker glossaire
- Dockerfile syntaxe
- determine the parent image
- docker image from scratch
- build context and image context
- nginx begginer guide
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
- official nginx docker image
- "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'"
- "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"
install and use docker and compose
- how to install docker engine
- github releases
- install last version of compose manually
- install manually SO discussion
- correct release version name for download with a 'v'
- the version installed with apt is 1.17.1, way out of date
remove old versions
sudo apt remove docker docker-engine docker.io containerd runcpreparing directorysudo apt updatesudo apt install ca-certificates curl gnupg lsb-releasesudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullinstalling docker enginesudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugincheck if installation workedsudo docker run hello-worldinstalling docker compose checked version on github release, see above- notice the 'v' below, before the version name (docker doc has it wong)
sudo curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-composebuild and run a docker image- be in directory with a Dockerfile
sudo docker build --tag <name> .sudo docker run <name>sudo docker imagesto list docker imagessudo docker image rm <number>sudo docker psto list docker processessudo docker ps rm <name>execute a docker-compose file- be in directory with a docker-compose.yml file
sudo docker-compose up
volumes vs bind mounts
- docker doc: use volumes
- docker doc: use bind mounts
- comparison volume vs bind mounts
- fundamentals use of volumes and bind mounts
- how volumes and bind mounts are really differents
- bind mounts are normal files anywhere on the computer, that docker container can access with absolut path and modify. They can also be modified without docker, since they are juste files
- volumes are only modifiable by docker, they don't need an absolut path, and they are not dependent of host architecture
tips
Description
Languages
Dockerfile
62.6%
Makefile
20.3%
Shell
15.4%
Assembly
1.6%
HTML
0.1%