Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
ACraig7 edited this page Nov 20, 2024 · 32 revisions

Table of Contents

  1. Installation
  2. Configuration
  3. Implementation
  4. Usage
  5. Troubleshooting

Installation

Installing Docker on Windows

Download the Docker Desktop for Windows from the official website. Run the installer and follow the on-screen instructions. After installation, verify Docker is working by opening a command prompt and typing:

docker --version

Installing Docker on Mac

Download Docker Desktop for Mac from the Docker website. Open the downloaded .dmg file and drag Docker to the Applications folder. Start Docker, and run the following command in Terminal to verify the installation:

docker --version

Installing Docker on Linux

Use the following commands to install Docker on a Debian-based system:

sudo apt-get update
sudo apt-get install -y docker.io

To verify Docker installation, type:

docker --version

For other Linux distributions, refer to the Docker Linux Installation Guide.

Using Docker Desktop

Docker Desktop simplifies Docker installation and management. It is available for both Windows and Mac. Read more about Docker Desktop.


Configuration

Configuring Docker Network

Docker uses a bridge network by default. You can create custom networks to connect containers:

docker network create my-network

Configuring Docker Volumes

Docker volumes are used to persist data between container restarts. Create a volume using:

docker volume create my-volume

Environment Variables

Pass environment variables to containers using the -e option:

docker run -e MY_VARIABLE=value my-container

Working Directory

Set the applications working directory:

WORKDIR /app

image

Docker Entry Point and Execution

Set the python as the program to execute when the container starts:

ENTRYPOINT ["python'] 

Set the default script that python should run:

CMD ["app.py"]

image


Implementation

Creating a Dockerfile The Dockerfile defines how your application runs inside a container. Here's an example for a basic Python application: img png

A Dockerfile is a script that contains instructions on how to build a Docker image.

 # Use Python as the base image
 FROM python:3.10-slim

 # Set the working directory in the container
 WORKDIR /app

 # Install the dependencies
 RUN pip install --no-cache-dir -r requirements.txt

 # Streamlit port
 EXPOSE 5001

 # Set default commands to run the application
 ENTRYPOINT ["python"]
 CMD ["app.py"]

Building and Running Containers Build the image:

docker build -t team1_app:latest .

build

docker run -d -p 5001:5001 team1_app

run

Can confirm the docker container running in docker app DD

making the application accessible via http://localhost:5001/team1/ app


Usage

Common Commands

Start a container:

docker start <container_id>

start

Stop a container:

docker stop <container_id>

stop

Remove a container:

docker rm <container_id>

rm

Managing Containers

List all containers:

docker ps -a

ps

Inspect a container:

docker inspect <container_id>

inspect


Troubleshooting

Common Issues

Issue: Docker daemon not starting. Solution: Restart the Docker service:

sudo systemctl restart docker

Debugging

Check Docker logs for detailed error information:

docker logs <container_id>

Performance Optimization

Allocate more resources to Docker in the Docker Desktop settings.

Logs and Monitoring

Access container logs using:

docker logs <container_id>

logs