diff --git a/eg3/README.md b/eg3/README.md index 743068d..bc4ed8f 100644 --- a/eg3/README.md +++ b/eg3/README.md @@ -2,3 +2,10 @@ [How To Run Multiple Docker Containers Under One URL](https://codingwithmanny.medium.com/create-an-nginx-reverse-proxy-with-docker-a1c0aa9078f1) +## Backend only + +How to test it: + +1. Comment all other containers +2. Run `docker compose build` & `docker compose up` +3. Test by `curl localhost:5000`, should return `{"version":"1.0.0"}` \ No newline at end of file diff --git a/eg3/backend/docker-compose.yaml b/eg3/backend/docker-compose.yaml deleted file mode 100644 index 43eae2c..0000000 --- a/eg3/backend/docker-compose.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3.8' - -services: - backend: - container_name: backend - build: . - ports: - - "5000:5000" \ No newline at end of file diff --git a/eg3/docker-compose.yaml b/eg3/docker-compose.yaml new file mode 100644 index 0000000..18bfb41 --- /dev/null +++ b/eg3/docker-compose.yaml @@ -0,0 +1,27 @@ +version: '3.8' + +services: + # proxy: + # container_name: proxy + # build: + # context: ./proxy + # dockerfile: Dockerfile + # ports: + # - "80:80" + # depends_on: + # - frontend + # - backend + + # frontend: + # container_name: frontend + # build: + # context: ./frontend + # dockerfile: Dockerfile + + backend: + container_name: backend + build: + context: ./backend + dockerfile: Dockerfile + ports: + - "5000:5000" # Uncomment this line if you want to run the backend container only \ No newline at end of file diff --git a/eg3/frontend/docker-compose.yaml b/eg3/frontend/docker-compose.yaml deleted file mode 100644 index ace46c8..0000000 --- a/eg3/frontend/docker-compose.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3.8' - -services: - frontend: - container_name: frontend - build: . - # ports: - # - "80:80" \ No newline at end of file diff --git a/eg3/proxy/Dockerfile b/eg3/proxy/Dockerfile index 57f5b46..439317a 100644 --- a/eg3/proxy/Dockerfile +++ b/eg3/proxy/Dockerfile @@ -1,4 +1,9 @@ FROM nginx:stable-alpine -WORKDIR /etc/nginx/conf.d -COPY default.conf . -CMD [ "nginx", "-s", "reload"] \ No newline at end of file +COPY default.conf /etc/nginx/conf.d + +EXPOSE 80/tcp +EXPOSE 443/tcp + +CMD [ "/bin/sh", "-c", "exec nginx -g 'daemon off;';"] + +WORKDIR /usr/share/nginx/html \ No newline at end of file diff --git a/eg3/proxy/default.conf b/eg3/proxy/default.conf index 576e8d0..8fef030 100644 --- a/eg3/proxy/default.conf +++ b/eg3/proxy/default.conf @@ -1,6 +1,5 @@ server { listen 80; - listen [::]:80; server_name localhost; location / { diff --git a/eg3/proxy/docker-compose.yaml b/eg3/proxy/docker-compose.yaml deleted file mode 100644 index acd2a34..0000000 --- a/eg3/proxy/docker-compose.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3.8' - -services: - proxy: - container_name: proxy - build: . - ports: - - "80:80" \ No newline at end of file