This guide provides step-by-step instructions for building and running the PictoPy backend using Docker.
- Prerequisites
- Building the Docker Image
- Running the Docker Container
- Verifying the Container
- Accessing the Application
- Stopping the Container
- Troubleshooting
Before you begin, ensure you have the Docker installed on your machine
- Verify the installation by running:
docker --version
-
Open a terminal and navigate to your project's root directory.
-
Go to Backend directory
cd backend
-
Run the following command to build the Docker image, replacing
<image_name>
with your desired image name:docker build -t <image_name> .
-
Wait for the build process to complete. This may take a few minutes depending on your internet speed and system performance.
Once the image is built, you can run a container using the following command:
docker run -d -p 8000:8000 --name <container_name> <image_name>
-d
: Runs the container in detached mode (in the background).-p 8000:8000
: Maps port 8000 on the host to port 8000 in the container.--name <container_name>
: Names the container for easier management.<image_name>
: Specifies the image to use (the one we just built).
To check if the container is running:
docker ps
You should see an entry for <container_name>
with the status Up
.
Open a web browser or frontend to access the application at:
http://localhost:8000
If you need to stop the container:
docker kill <container_id>
-
Port already in use: If you get an error saying the port is already in use, you can either:
- Stop the process using port 8000, or
- Change the port mapping in the
docker run
command (e.g.,-p 8001:8000
)
-
Container exits immediately: Check the container logs:
docker logs <container_name>
-
Permission issues: Ensure that
run.sh
has execute permissions(for linux only):chmod +x run.sh
Then rebuild the Docker image.
Remember to rebuild your Docker image (docker build -t <image_name> .
) after making any changes to your application or Dockerfile.
For more advanced Docker usage , view the Docker documentation.