-
Notifications
You must be signed in to change notification settings - Fork 1
Docker
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
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
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.
Docker Desktop simplifies Docker installation and management. It is available for both Windows and Mac. Read more about Docker Desktop.
Docker uses a bridge network by default. You can create custom networks to connect containers:
docker network create my-network
Docker volumes are used to persist data between container restarts. Create a volume using:
docker volume create my-volume
Pass environment variables to containers using the -e
option:
docker run -e MY_VARIABLE=value my-container
Set the applications working directory:
WORKDIR /app
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"]
Creating a Dockerfile The Dockerfile defines how your application runs inside a container. Here's an example for a basic Python application:
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 .
docker run -d -p 5001:5001 team1_app
Can confirm the docker container running in docker app
making the application accessible via http://localhost:5001/team1/
Start a container:
docker start <container_id>
Stop a container:
docker stop <container_id>
Remove a container:
docker rm <container_id>
List all containers:
docker ps -a
Inspect a container:
docker inspect <container_id>
Issue: Docker daemon not starting. Solution: Restart the Docker service:
sudo systemctl restart docker
Check Docker logs for detailed error information:
docker logs <container_id>
Allocate more resources to Docker in the Docker Desktop settings.
Access container logs using:
docker logs <container_id>