diff --git a/README.md b/README.md index 9fc1dbb..b6d95ff 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,13 @@ This README would normally document whatever steps are necessary to get your app - ? 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 -tulpn` to print network connections and see if nginx is running +- or : `ps -ax | grep nginx` +- `sudo nginx -s quit` to stop it + --- ## Dockerfile basics @@ -16,62 +23,9 @@ This README would normally document whatever steps are necessary to get your app - we need to copy the files it uses inside this filesystem - we can do that with COPY -**working** -``` -FROM scratch -WORKDIR / -COPY hello / -CMD [ "/hello" ] -``` - -**working, when WORKDIR is absent, it's default is set to "/"** -``` -FROM scratch -COPY hello / -CMD [ "/hello" ] -``` - -**not working, when CMD execute in shell form, instead of exec form []** -``` -FROM scratch -COPY hello / -CMD /hello -``` - -**not working, because c executable need library ** -``` -FROM scratch -COPY hello_c / -CMD [ "/hello_c" ] -``` - -**not working, when executable is copied to ".", because WORKDIR value is not "." but "/" since we gave it a relativ path so it was build in top of the implicit absolut path "/"** -``` -FROM scratch -WORKDIR . -COPY hello . -CMD [ "hello" ] -``` - -**not working, when WORKDIR is set to the present directory and executable is not copied, because the workdir is not the present directory but a directory in the file system of docker : executable need to be copied there to function** -``` -FROM scratch -WORKDIR /home/simplonco/Desktop/42/14_inception/inception/srcs/requirements/mariadb -CMD [ "hello" ] -``` - -**working, because "hello" is copied to "/" and execute from "/"** -``` -FROM scratch -WORKDIR . -COPY hello / -CMD [ "/hello" ] -``` - --- ## ressources -- [how to install docker engine](https://docs.docker.com/engine/install/ubuntu/) - [download alpine linux](https://alpinelinux.org/downloads/) - [dockerhub alpine image](https://hub.docker.com/_/alpine) - [docker glossaire](https://docs.docker.com/glossary/) @@ -79,13 +33,42 @@ CMD [ "/hello" ] - [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) +- [pid1 docker problem](https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/) -#### docker compose +#### install and use docker and compose +- [how to install docker engine](https://docs.docker.com/engine/install/ubuntu/) - [github releases](https://github.com/docker/compose/releases) - [install last version of compose manually](https://docs.docker.com/compose/install/compose-plugin/#install-the-plugin-manually) - [install manually SO discussion](https://stackoverflow.com/questions/57456212/error-version-in-docker-compose-yml-is-unsupported) -- the version installed with is 1.17.1, way out of date +- 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 runc` +**preparing directory** +- `sudo apt update` +- `sudo apt install ca-certificates curl gnupg lsb-release` +- `sudo mkdir -p /etc/apt/keyrings` +- `curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg` +- `echo "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/null` +**installing docker engine** +- `sudo apt update` +- `sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin` +**check if installation worked** +- `sudo docker run hello-world` +**installing docker compose** checked version on github release, see above +- `sudo curl -L "https://github.com/docker/compose/releases/download/2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose` +- `sudo chmod +x /usr/local/bin/docker-compose` +- `sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose` +**build and run a docker image** +- be in directory with a Dockerfile +- `sudo docker build --tag .` +- `sudo docker images` to list images +- `sudo docker run ` +- `sudo docker image rm -f ` +**execute a docker-compose file** +- be in directory with a docker-compose.yml file +- `sudo docker-compose up` #### volumes vs bind mounts diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 36499fa..02267bc 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -4,6 +4,7 @@ # had to remove the apt version because it was not up to date (sudo apt remove docker-compose) # then install as recommended : curl -SL https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose # or (neat) : https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose + version: "3.8" services: diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index e69de29..d3dc63f 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -0,0 +1,11 @@ +FROM debian:buster + +RUN apt update && apt install -y nginx + +COPY ./conf/nginx.conf /etc/nginx/ +COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ +COPY ./conf/index.html /data/www/ +COPY ./conf/salade.jpeg /data/images/ + +CMD [ "nginx" ] + diff --git a/srcs/requirements/nginx/conf/inception_nginx.conf b/srcs/requirements/nginx/conf/inception_nginx.conf new file mode 100644 index 0000000..6dee8d9 --- /dev/null +++ b/srcs/requirements/nginx/conf/inception_nginx.conf @@ -0,0 +1,9 @@ +server { + server_name localhost; + location / { + root /data/www; + } + location /images/ { + root /data; + } +} diff --git a/srcs/requirements/nginx/conf/index.html b/srcs/requirements/nginx/conf/index.html new file mode 100644 index 0000000..a95200f --- /dev/null +++ b/srcs/requirements/nginx/conf/index.html @@ -0,0 +1 @@ +hello world ! diff --git a/srcs/requirements/nginx/conf/nginx.conf b/srcs/requirements/nginx/conf/nginx.conf new file mode 100644 index 0000000..b21ef82 --- /dev/null +++ b/srcs/requirements/nginx/conf/nginx.conf @@ -0,0 +1,85 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} + + +#mail { +# # See sample authentication script at: +# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript +# +# # auth_http localhost/auth.php; +# # pop3_capabilities "TOP" "USER"; +# # imap_capabilities "IMAP4rev1" "UIDPLUS"; +# +# server { +# listen localhost:110; +# protocol pop3; +# proxy on; +# } +# +# server { +# listen localhost:143; +# protocol imap; +# proxy on; +# } +#} + diff --git a/srcs/requirements/nginx/conf/salade.jpeg b/srcs/requirements/nginx/conf/salade.jpeg new file mode 100644 index 0000000..92d1e01 Binary files /dev/null and b/srcs/requirements/nginx/conf/salade.jpeg differ diff --git a/srcs/requirements/test/Dockerfile b/srcs/requirements/test/Dockerfile index dd9a770..070a86e 100644 --- a/srcs/requirements/test/Dockerfile +++ b/srcs/requirements/test/Dockerfile @@ -12,3 +12,41 @@ FROM scratch COPY tools/hello / CMD [ "/hello" ] +## working +#FROM scratch +#WORKDIR / +#COPY hello / +#CMD [ "/hello" ] + +## working, when WORKDIR is absent, it's default is set to "/" +#FROM scratch +#COPY hello / +#CMD [ "/hello" ] + +## not working, when CMD execute in shell form, instead of exec form [] +#FROM scratch +#COPY hello / +#CMD /hello + +## not working, because c executable need library +#FROM scratch +#COPY hello_c / +#CMD [ "/hello_c" ] + +## not working, when executable is copied to ".", because WORKDIR value is not "." but "/" since we gave it a relativ path so it was build in top of the implicit absolut path "/" +#FROM scratch +#WORKDIR . +#COPY hello . +#CMD [ "hello" ] + +## not working, when WORKDIR is set to the present directory and executable is not copied, because the workdir is not the present directory but a directory in the file system of docker : executable need to be copied there to function +#FROM scratch +#WORKDIR /home/simplonco/Desktop/42/14_inception/inception/srcs/requirements/mariadb +#CMD [ "hello" ] + +## working, because "hello" is copied to "/" and execute from "/" +#FROM scratch +#WORKDIR . +#COPY hello / +#CMD [ "/hello" ] +