From 638167cbc2fcaf242a54fea90e4c67b013a96d2b Mon Sep 17 00:00:00 2001 From: estellon Date: Wed, 17 Jul 2024 18:53:20 +0200 Subject: [PATCH 1/2] add_README --- README.md | 107 ++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 4 +- helloworld/views.py | 2 +- makefile | 4 +- 4 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cc4390 --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ +# Installing Docker and Docker Compose on Ubuntu + +This guide will help you install Docker and Docker Compose on an Ubuntu system. + +## Prerequisites + +- A system running Ubuntu (preferably 20.04 LTS or later) +- A user account with `sudo` privileges + +## Installing Docker + +1. **Update the package index:** + + ```bash + sudo apt update + ``` + +2. **Install required packages:** + + ```bash + sudo apt install apt-transport-https ca-certificates curl software-properties-common + ``` + +3. **Add Docker's official GPG key:** + + ```bash + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + ``` + +4. **Set up the Docker repository:** + + ```bash + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + ``` + +5. **Update the package index again:** + + ```bash + sudo apt update + ``` + +6. **Install Docker CE:** + + ```bash + sudo apt install docker-ce + ``` + +7. **Check the Docker service status:** + + ```bash + sudo systemctl status docker + ``` + +8. **Add your user to the `docker` group to run Docker commands without `sudo`:** + + ```bash + sudo usermod -aG docker $USER + ``` + +9. **Log out and log back in to apply the group changes.** + +## Installing Docker Compose + +1. **Download Docker Compose:** + + ```bash + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + ``` + +2. **Apply executable permissions to the Docker Compose binary:** + + ```bash + sudo chmod +x /usr/local/bin/docker-compose + ``` + +3. **Verify the installation:** + + ```bash + docker-compose --version + ``` + +## Verifying Docker and Docker Compose Installation + +1. **Run a simple Docker container:** + + ```bash + docker run hello-world + ``` + + This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message. + +2. **Check Docker Compose version:** + + ```bash + docker-compose --version + ``` + + This command outputs the version of Docker Compose installed. + +Congratulations! You have successfully installed Docker and Docker Compose on your Ubuntu system. + +## Additional Resources + +- [Docker Documentation](https://docs.docker.com/) +- [Docker Compose Documentation](https://docs.docker.com/compose/) + + diff --git a/docker-compose.yaml b/docker-compose.yaml index d67d45c..453a86e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -52,13 +52,13 @@ volumes: driver: local driver_opts: type: none - device: /home/motoko/ft_transcendence/data/db + device: /home/yannick/42/ft_transcendence/data/db o: bind helloword_project: driver: local driver_opts: type: none - device: /home/motoko/ft_transcendence/helloworld + device: /home/yannick/42/ft_transcendence/helloworld o: bind networks: diff --git a/helloworld/views.py b/helloworld/views.py index ceff077..009ec84 100644 --- a/helloworld/views.py +++ b/helloworld/views.py @@ -1,4 +1,4 @@ from django.http import HttpResponse def index(request): - return HttpResponse("Hello, CHAKIB!") + return HttpResponse("Hello, CHAKIB est une trompette!") diff --git a/makefile b/makefile index e892915..4aaf418 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ all: build @echo "Building Docker images..." - sudo mkdir -p $$HOME/ft_transcendence/data/db + sudo mkdir -p $$PWD/data/db sudo docker compose -f ./docker-compose.yaml up -d --build down: @@ -15,7 +15,7 @@ clean: sudo docker rm $$(docker ps -qa);\ sudo docker rmi $$(docker image ls -q);\ sudo docker volume rm $$(docker volume ls -q);\ - sudo rm -rf $$HOME/ft_transcendence/data/db ;\ + sudo rm -rf $$PWd/data/db ;\ logs: @echo "Displaying Docker logs..." From b5bc219cd625e33582e7f284fcce130a0630b1a8 Mon Sep 17 00:00:00 2001 From: Adrien Audebert Date: Thu, 18 Jul 2024 13:55:01 +0200 Subject: [PATCH 2/2] update --- Dockerfile | 8 ------- README.md | 36 ++++++++++++++++++++++++++++++ docker-compose.yaml | 5 +++-- env_template | 5 ++++- helloworld/views.py | 2 +- makefile | 54 +++++++++++++++++++++++++++++++-------------- 6 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 README.md diff --git a/Dockerfile b/Dockerfile index ce4e9e3..e551db2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ FROM python:3.12.4 WORKDIR /ft_transcendence RUN apt update && apt upgrade -y -RUN apt install -y vim COPY requirements.txt . COPY manage.py . @@ -12,11 +11,4 @@ RUN python3 -m venv venv RUN venv/bin/pip3 install --upgrade pip RUN venv/bin/pip3 install --no-cache-dir -r requirements.txt -COPY . . - -#RUN venv/bin/python3 manage.py migrate --noinput -#RUN venv/bin/python manage.py collectstatic --noinput - EXPOSE 8000 - -CMD ["venv/bin/python", "manage.py", "runserver", "0.0.0.0:8000"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..375af57 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Installing Docker and Docker Compose on Ubuntu + +This guide will help you install Docker and Docker Compose on an Ubuntu system. + +## Prerequisites + +- A system running Ubuntu (preferably 20.04 LTS or later) +- A user account with `sudo` privileges + +## Installing Docker + +1. **Update the package index:** + +```bash +sudo apt update + +sudo apt install apt-transport-https ca-certificates curl software-properties-common + +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + +sudo apt update + +sudo apt install docker-ce + +sudo systemctl status docker + +sudo usermod -aG docker $USER + +sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + +sudo chmod +x /usr/local/bin/docker-compose + +docker compose version + diff --git a/docker-compose.yaml b/docker-compose.yaml index d67d45c..0c2b571 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,6 +27,7 @@ services: container_name: backend restart: always command: /bin/sh -c "sleep 5 && venv/bin/python3 manage.py migrate --noinput && venv/bin/python3 manage.py runserver 0.0.0.0:8000" + #&& venv/bin/python manage.py collectstatic --noinput volumes: - helloword_project:/ft_transcendence/helloworld ports: @@ -52,13 +53,13 @@ volumes: driver: local driver_opts: type: none - device: /home/motoko/ft_transcendence/data/db + device: ${POSTGRES_DATA_PATH} o: bind helloword_project: driver: local driver_opts: type: none - device: /home/motoko/ft_transcendence/helloworld + device: ${PROJECT_PATH} o: bind networks: diff --git a/env_template b/env_template index eaef9b2..6cfd911 100644 --- a/env_template +++ b/env_template @@ -4,9 +4,12 @@ DEBUG=True DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] # PostgreSQL settings -POSTGRES_DB= +POSTGRES_DB= POSTGRES_USER= POSTGRES_PASSWORD= DB_HOST=db DB_PORT=5432 + +PROJECT_PATH=${PWD}/helloworld +POSTGRES_DATA_PATH=${PWD}/data/db diff --git a/helloworld/views.py b/helloworld/views.py index ceff077..9faf885 100644 --- a/helloworld/views.py +++ b/helloworld/views.py @@ -1,4 +1,4 @@ from django.http import HttpResponse def index(request): - return HttpResponse("Hello, CHAKIB!") + return HttpResponse("Hello, QWER!") diff --git a/makefile b/makefile index e892915..ca790f2 100644 --- a/makefile +++ b/makefile @@ -1,24 +1,44 @@ -.PHONY: all build down clean logs +COMPOSE_FILE=docker-compose.yaml +COMPOSE=docker compose -f $(COMPOSE_FILE) +CONTAINER=$(c) -all: build - @echo "Building Docker images..." - sudo mkdir -p $$HOME/ft_transcendence/data/db - sudo docker compose -f ./docker-compose.yaml up -d --build +up: + sudo mkdir -p $$PWD/data/db + $(COMPOSE) build + $(COMPOSE) up -d $(CONTAINER) + +build: + $(COMPOSE) build $(CONTAINER) + +start: + $(COMPOSE) start $(CONTAINER) + +stop: + $(COMPOSE) stop $(CONTAINER) down: - @echo "Stopping Docker containers..." - sudo docker compose -f ./docker-compose.yaml down + $(COMPOSE) down $(CONTAINER) -clean: - @echo "Cleaning up Docker resources..." - sudo docker stop $$(docker ps -qa);\ - sudo docker rm $$(docker ps -qa);\ - sudo docker rmi $$(docker image ls -q);\ - sudo docker volume rm $$(docker volume ls -q);\ - sudo rm -rf $$HOME/ft_transcendence/data/db ;\ +destroy: + $(COMPOSE) down -v --rmi all + sudo rm -rf $$PWD/data/db logs: - @echo "Displaying Docker logs..." - sudo docker compose logs -f + $(COMPOSE) logs -f $(CONTAINER) + +ps: + $(COMPOSE) ps + +help: + @echo "Usage:" + @echo " make build [c=service] # Build images" + @echo " make up [c=service] # Start containers in detached mode" + @echo " make start [c=service] # Start existing containers" + @echo " make down [c=service] # Stop and remove containers" + @echo " make destroy # Stop and remove containers and volumes" + @echo " make stop [c=service] # Stop containers" + @echo " make restart [c=service] # Restart containers" + @echo " make logs [c=service] # Tail logs of containers" + @echo " make ps # List containers" + @echo " make help # Show this help" -re: down clean build