Docker - DrAlzahraniProjects/csusb_fall2024_cse6550_team2 GitHub Wiki


1. Installation

Docker Setup on macOS

  1. Download Docker Desktop

  2. Install Docker Desktop

    • Open the .dmg file, drag Docker to the Applications folder, and follow the setup instructions.
  3. Verify Installation

    • Run the following command:
      docker --version
      

2. Configuration

Docker Daemon Settings

  1. Access Preferences > Docker Engine in Docker Desktop to edit settings like CPU, memory, and disk allocation.

Useful Docker Commands:

  • Start Docker Daemon (if not automatically running):

    open -a Docker
    
  • Check Docker Daemon Status:

    docker info
    

3. Implementation

Role of Docker in My Project

  1. Create Dockerfile
    This is the Dockerfile used in the project:

    FROM python:3.10-slim
    WORKDIR /app
    COPY requirements.txt /app/requirements.txt
    RUN pip install -r requirements.txt
    COPY . /app
    ENTRYPOINT ["python"]
    CMD ["app.py"]
    
  1. Build Docker Image
    Use the following command to build the Docker image for the app:
    docker build -t team2-app .
    
  1. Run Docker Container
    To run the container:
    docker run -d -p 5000:5000 team2-app
    
    This exposes the app on port 5000.
  1. Container is running in the docker app
  1. Application is running on http://localhost:5002/team2/

4. Usage

Common Docker Commands in Project

  • List Running Containers:

    docker ps
    
  • Stop a Container:

    docker stop <container_id>
    
  • Remove a Container:

    docker rm <container_id>
    
  • Check Logs of a Container:

    docker logs <container_id>
    

5. Troubleshooting

Common Issues Faced:

  • Docker Daemon Not Running
    Solution: Restart Docker Desktop or run:

    open -a Docker
    
  • Port Already in Use
    Solution: Use a different port when running:

    docker run -d -p 5001:5000 team2-app
    
  • Permission Errors
    Solution: Adjust user permissions with:

    docker run --user $(id -u):$(id -g) -v $(pwd):/app team2-app
    
  • Increase Resources
    Solution: Adjust memory and CPU in Preferences > Resources.