|
1 | | -# Backend Docker Setup for PictoPy |
2 | | - |
3 | | -This guide provides step-by-step instructions for building and running the PictoPy backend using Docker. |
4 | | - |
5 | | -## Table of Contents |
6 | | - |
7 | | -1. [Prerequisites](#prerequisites) |
8 | | -2. [Building the Docker Image](#building-the-docker-image) |
9 | | -3. [Running the Docker Container](#running-the-docker-container) |
10 | | -4. [Verifying the Container](#verifying-the-container) |
11 | | -5. [Accessing the Application](#accessing-the-application) |
12 | | -6. [Stopping the Container](#stopping-the-container) |
13 | | -7. [Troubleshooting](#troubleshooting) |
14 | | - |
15 | | -## Prerequisites |
16 | | - |
17 | | -Before you begin, ensure you have the Docker installed on your machine |
18 | | - |
19 | | -- Verify the installation by running: |
20 | | - ```bash |
21 | | - docker --version |
22 | | - ``` |
23 | | - |
24 | | -## Building the Docker Image |
25 | | - |
26 | | -1. Open a terminal and navigate to your project's root directory. |
27 | | - |
28 | | -2. Go to Backend directory |
29 | | - |
30 | | - ```bash |
31 | | - cd backend |
32 | | - ``` |
33 | | - |
34 | | -3. Run the following command to build the Docker image, replacing `<image_name>` with your desired image name: |
35 | | - |
36 | | - ```bash |
37 | | - docker build -t <image_name> . |
38 | | - ``` |
39 | | - |
40 | | -4. Wait for the build process to complete. This may take a few minutes depending on your internet speed and system performance. |
41 | | - |
42 | | -## Running the Docker Container |
43 | | - |
44 | | -Once the image is built, you can run a container using the following command: |
45 | | - |
46 | | -```bash |
47 | | -docker run -it --name backend-container -p 8000:8000 \ |
48 | | --v images-data:/app/images \ |
49 | | --v /:/host \ |
50 | | -<image-name> |
51 | | -``` |
52 | | - |
53 | | -- `-it`: Runs the container interactively, attaching to the terminal for input/output. |
54 | | -- `-p 8000:8000`: Maps port 8000 on the host to port 8000 in the container. |
55 | | -- `-v`: Mounts a volume to share data between the host and container. |
56 | | -- `<image_name>`: Specifies the image to use (the one we just built). |
57 | | - |
58 | | -## Verifying the Container |
59 | | - |
60 | | -To check if the container is running: |
61 | | - |
62 | | -```bash |
63 | | -docker ps |
64 | | -``` |
65 | | - |
66 | | -You should see an entry for `<container_name>` with the status `Up`. |
67 | | - |
68 | | -## Accessing the Application |
69 | | - |
70 | | -Open a web browser or frontend to access the application at: |
71 | | - |
72 | | -``` |
73 | | -http://localhost:8000 |
74 | | -``` |
75 | | - |
76 | | -## Stopping the Container |
77 | | - |
78 | | -If you need to stop the container: |
79 | | - |
80 | | -```bash |
81 | | -docker kill <container_id> |
82 | | -``` |
83 | | - |
84 | | -## Troubleshooting |
85 | | - |
86 | | -1. **Port already in use**: If you get an error saying the port is already in use, you can either: |
87 | | - |
88 | | - - Stop the process using port 8000, or |
89 | | - - Change the port mapping in the `docker run` command (e.g., `-p 8001:8000`) |
90 | | - |
91 | | -2. **Container exits immediately**: Check the container logs: |
92 | | - |
93 | | - ```bash |
94 | | - docker logs <container_name> |
95 | | - ``` |
96 | | - |
97 | | -3. **Permission issues**: Ensure that `run.sh` has execute permissions(for linux only): |
98 | | - |
99 | | - ```bash |
100 | | - chmod +x run.sh |
101 | | - ``` |
102 | | - |
103 | | - Then rebuild the Docker image. |
104 | | - |
105 | | -Remember to rebuild your Docker image (`docker build -t <image_name> .`) after making any changes to your application or Dockerfile. |
106 | | - |
107 | | -For more advanced Docker usage , view the [Docker documentation](https://docs.docker.com/get-started/). |
| 1 | +# Backend Docker Setup for PictoPy |
| 2 | + |
| 3 | +This guide provides step-by-step instructions for building and running the PictoPy backend using Docker. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +1. [Prerequisites](#prerequisites) |
| 8 | +2. [Building the Docker Image](#building-the-docker-image) |
| 9 | +3. [Running the Docker Container](#running-the-docker-container) |
| 10 | +4. [Verifying the Container](#verifying-the-container) |
| 11 | +5. [Accessing the Application](#accessing-the-application) |
| 12 | +6. [Stopping the Container](#stopping-the-container) |
| 13 | +7. [Troubleshooting](#troubleshooting) |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +Before you begin, ensure you have the Docker installed on your machine |
| 18 | + |
| 19 | +- Verify the installation by running: |
| 20 | + ```bash |
| 21 | + docker --version |
| 22 | + ``` |
| 23 | + |
| 24 | +## Building the Docker Image |
| 25 | + |
| 26 | +1. Open a terminal and navigate to your project's root directory. |
| 27 | + |
| 28 | +2. Go to Backend directory |
| 29 | + |
| 30 | + ```bash |
| 31 | + cd backend |
| 32 | + ``` |
| 33 | + |
| 34 | +3. Run the following command to build the Docker image, replacing `<image_name>` with your desired image name: |
| 35 | + |
| 36 | + ```bash |
| 37 | + docker build -t <image_name> . |
| 38 | + ``` |
| 39 | + |
| 40 | +4. Wait for the build process to complete. This may take a few minutes depending on your internet speed and system performance. |
| 41 | + |
| 42 | +## Running the Docker Container |
| 43 | + |
| 44 | +Once the image is built, you can run a container using the following command: |
| 45 | + |
| 46 | +```bash |
| 47 | +docker run -it --name backend-container -p 8000:8000 \ |
| 48 | +-v images-data:/app/images \ |
| 49 | +-v /:/host \ |
| 50 | +<image-name> |
| 51 | +``` |
| 52 | + |
| 53 | +- `-it`: Runs the container interactively, attaching to the terminal for input/output. |
| 54 | +- `-p 8000:8000`: Maps port 8000 on the host to port 8000 in the container. |
| 55 | +- `-v`: Mounts a volume to share data between the host and container. |
| 56 | +- `<image_name>`: Specifies the image to use (the one we just built). |
| 57 | + |
| 58 | +## Verifying the Container |
| 59 | + |
| 60 | +To check if the container is running: |
| 61 | + |
| 62 | +```bash |
| 63 | +docker ps |
| 64 | +``` |
| 65 | + |
| 66 | +You should see an entry for `<container_name>` with the status `Up`. |
| 67 | + |
| 68 | +## Accessing the Application |
| 69 | + |
| 70 | +Open a web browser or frontend to access the application at: |
| 71 | + |
| 72 | +``` |
| 73 | +http://localhost:8000 |
| 74 | +``` |
| 75 | + |
| 76 | +## Stopping the Container |
| 77 | + |
| 78 | +If you need to stop the container: |
| 79 | + |
| 80 | +```bash |
| 81 | +docker kill <container_id> |
| 82 | +``` |
| 83 | + |
| 84 | +## Troubleshooting |
| 85 | + |
| 86 | +1. **Port already in use**: If you get an error saying the port is already in use, you can either: |
| 87 | + |
| 88 | + - Stop the process using port 8000, or |
| 89 | + - Change the port mapping in the `docker run` command (e.g., `-p 8001:8000`) |
| 90 | + |
| 91 | +2. **Container exits immediately**: Check the container logs: |
| 92 | + |
| 93 | + ```bash |
| 94 | + docker logs <container_name> |
| 95 | + ``` |
| 96 | + |
| 97 | +3. **Permission issues**: Ensure that `run.sh` has execute permissions(for linux only): |
| 98 | + |
| 99 | + ```bash |
| 100 | + chmod +x run.sh |
| 101 | + ``` |
| 102 | + |
| 103 | + Then rebuild the Docker image. |
| 104 | + |
| 105 | +Remember to rebuild your Docker image (`docker build -t <image_name> .`) after making any changes to your application or Dockerfile. |
| 106 | + |
| 107 | +For more advanced Docker usage , view the [Docker documentation](https://docs.docker.com/get-started/). |
0 commit comments