Working woth Docker


docker run hello-world

List Running Containers

bash

Copy code

docker ps

Stop a Container

bash

Copy code

docker stop [CONTAINER_ID]

Remove a Container

bash

Copy code

docker rm [CONTAINER_ID]

List All Containers

bash

Copy code

docker ps -a

Build an Image

bash

Copy code

docker build -t my-image .

Run a Container from an Image

bash

Copy code

docker run -d -p 8080:80 my-image

Pull an Image from Docker Hub

bash

Copy code

docker pull nginx

Push an Image to Docker Hub

bash

Copy code

docker push [USERNAME]/my-image

6. Writing a Dockerfile

A Dockerfile is used to build custom images. Below is an example for a Python application:

Example:

dockerfile

Copy code

# Base image FROM python:3.9-slim # Set working directory WORKDIR /app # Copy application files COPY . /app # Install dependencies RUN pip install -r requirements.txt # Expose port EXPOSE 5000 # Run the application CMD ["python", "app.py"]

Build and Run the Docker Image

  1. Build the image:

    bash

    Copy code

    docker build -t my-python-app .

  2. Run the container:

    bash

    Copy code

    docker run -p 5000:5000 my-python-app

7. Docker Compose

Docker Compose simplifies running multi-container applications using a single YAML configuration file.

Example docker-compose.yml:

yaml

Copy code

version: '3.8' services: web: image: nginx ports: - "8080:80" app: build: context: . volumes: - ./app:/app ports: - "5000:5000"

Run the services:

bash

Copy code

docker-compose up

8. Advanced Topics


Newsletter

Wexdi SoftSkills

Our mission is to empower individuals with practical skills for success in the workplace. We aim to bridge the gap between academia and industry, offering hands-on learning experiences that meet the needs of the modern workforce

Legal & Accessibility

© 2025 Wexdi SoftSkills. All Rights Reserved.
Maintained by Wexdi Software Services | Release Version: 1.0.7

^