JustToThePoint English Website Version
JustToThePoint en español

Getting Started with Docker. Installation, Commands, and Containerized Applications

Introduction

Success is 80% psychology and 20% mechanics. You could master every strategy, but without a shift in your mindset, you won’t reach the top. 80% of our results come from 20% of our efforts, Anonymous

Docker is a powerful software platform designed to make it easier to create, deploy, and run applications by using containers. It offers OS-level virtualization to deliver software in packages called containers. Containers are lightweight, portable, and self-sufficient, which makes them an excellent choice for developing and deploying applications across various environments.

Image

Installing Docker

On Ubuntu

  1. First, we will update and upgrade the system: sudo apt-get update && sudo apt-get upgrade

  2. Let’s install Docker using the following command: sudo apt install docker.io. Let’s know the Docker version information: docker ‐‐version. Check whether Docker is running: sudo systemctl status docker

  3. We should start Docker and make it enable automatically on system boot: sudo systemctl enable ‐‐now docker.

  4. Add your user to the docker group: sudo usermod -aG docker ${USER}.

  5. It’s time to test it: docker run hello-world.

  6. Managing containers:

    docker container ls -a
    # List all containers
    docker container stop [container_id]
    # Stop a specific container.
    docker container stop $(docker container ls –aq)
    # Stop all containers.
    docker container rm [container_id]
    # Remove a stopped container
    rm $(docker container ls –aq)
    # Remove all containers: docker container .
    

Docker on Raspberry Pi

  1. First, we will update and upgrade the system: sudo apt-get update && sudo apt-get upgrade
  2. Download (curl) and execute the installation script: curl -sSL https://get.docker.com​ | sh
  3. Add a non-root user (pi) to the docker group: sudo usermod -aG docker pi
  4. Check Docker version (docker version) and test it by running the Hello World container: docker run hello-world

Docker on Arch

  1. Install the necessary packages: sudo pacman -Syy docker docker-compose
  2. Start the docker service on startup: sudo systemctl start docker.service, sudo systemctl enable docker.service
  3. Add our user to the Docker group: sudo usermod -aG docker $USER
  4. Test it: docker run hello-world

Essential Docker Commands

  1. docker run. Purpose: Create and start a container from an image. Example:

    docker run -d --name=web nginx
    

    This command starts an Nginx web server in detached mode (runs in the background) with the name “web”.

  2. docker pull. Purpose: Download an image (or update existing ones) from a registry like Docker Hub. Example:

    docker pull nginx:latest
    

    This command downloads the latest version of the Nginx image from Docker Hub.

  3. docker ps. Purpose: List currently running containers. Example:

    docker ps
    

    Output:

    CONTAINER ID   IMAGE                       COMMAND                  CREATED          STATUS          PORTS
                                              NAMES
    3e457e3d46a1   nginx                       "/docker-entrypoint.…"   3 minutes ago    Up 3 minutes    0.0.0.0:8080->80/tcp, :::8080->80/tcp                                 web
    18a5b83591dd   lscr.io/linuxserver/libreoffice:latest   "/init"            22 hours ago    Up 7 hours      0.0.0.0:3000-3001->3000-3001/tcp, :::3000-3001->3000-3001/tcp   libreoffice
    
  4. docker stop. Purpose: Gracefully stop a running container. Example:

    docker stop web
    

    This command stops the container named “web”.

  5. Removing a Container. Command:

    docker rm web
    

    Note: If you receive an error message like Error response from daemon: No such container: web, it typically means Docker has already removed the container. This can happen if the container was automatically cleaned up after stopping.

  6. Pruning Containers. Purpose: Forcefully removes all Docker containers on your system —both running and stopped. Command:

    docker container prune
    

    Note: This is a safe and standard way to clean up all containers if you want to start fresh or free up resources.

Writing a Dockerfile: Ubuntu Dashboard Example

Let’s take a look at how to deploy some popular applications using Docker:

docker run -it --rm -d -p 8080:80 --name web nginx
docker run -d \
  --name=firefox \
  --security-opt seccomp=unconfined \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Europe/Madrid \
  -e FIREFOX_CLI=https://www.linuxserver.io/ \
  -p 3000:3000 \
  -p 3001:3001 \
  --shm-size="1gb" \
  --restart unless-stopped \
  lscr.io/linuxserver/firefox:latest

This command sets up a Firefox container with specified configurations, ready for use in http://localhost:3000 or https://localhost:3001.

Dockerfile

  1. Create a new directory for your project: mkdir ubuntu-dashboard, cd ubuntu-dashboard

  2. Save a file Dockerfile in this directory. It creates a Ubuntu-based container that provides a comprehensive information dashboard displaying: current time and date; monthly calendar; weather information for Malaga, Spain; latest news headlines, and system information.

    # Ubuntu Information Dashboard Dockerfile
    
    # Uses Ubuntu 24.04 LTS as the base image for stability
    FROM ubuntu:24.04
    
    # Set environment variables to avoid interactive prompts during package installation
    ENV DEBIAN_FRONTEND=noninteractive
    
    # Sets timezone to Madrid (same timezone as Malaga)
    ENV TZ=Europe/Madrid
    
    # Update package list and install required packages
    RUN apt-get update && apt-get install -y \
        curl \ # Download data from APIs and websites
        jq \ #  Parse JSON data (for future API integrations)
        figlet \ # Create ASCII art text headers
        toilet \ # Create ASCII art text headers
        lolcat \ # Add colorful output
        ncal \ # Display calendar
        tzdata \ # Handle timezone data
        wget \ # Download data from APIs and websites
        python3 \ # For potential Python scripts
        python3-pip \
        locales \ # Handle text encoding
        xmlstarlet \
        ca-certificates \
        && rm -rf /var/lib/apt/lists/*
    
    # Set up locale and Timezone Configuration
    RUN locale-gen en_US.UTF-8 # Sets up proper text encoding
    ENV LANG=en_US.UTF-8
    # Configures the container to use Madrid timezone
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    
    # Create a directory for our scripts
    WORKDIR /app
    
    # Copy script files to container
    COPY dashboard.sh /app/dashboard.sh
    COPY run_once.sh /app/run_once.sh
    
    # Make scripts executable
    RUN chmod +x /app/dashboard.sh /app/run_once.sh
    
    # Expose port (optional, for future web interface)
    EXPOSE 8080
    
    # Default command - runs dashboard once
    CMD ["/app/run_once.sh"]
    
  3. Save a file dashboard.sh in this directory. This is the main dashboard script.

    #!/bin/bash
    
    # Colors for output
    RED='\033[0;31m' # Red color for error messages
    GREEN='\033[0;32m' # Green color for success messages
    YELLOW='\033[1;33m' # Yellow color for informational messages
    BLUE='\033[0;34m' # Blue color for headers
    PURPLE='\033[0;35m' # Purple color for decorative text
    CYAN='\033[0;36m' # Cyan color for emphasis
    NC='\033[0m' # No Color (reset to default)
    
    # Function to print colored headers
    print_header() {
        echo -e "\n${CYAN}=========================
        =======${NC}" # Print header line
        echo -e "${CYAN}$1${NC}" # Print the header text
        echo -e "${CYAN}================================${NC}"  # Print footer line
    }
    
    # Function to get weather for Malaga
    get_weather() {
        echo -e "${YELLOW}Getting weather for Malaga, Spain...${NC}"
    
        # Using wttr.in service for weather (no API key needed)
        weather_data=$(curl -s "wttr.in/Malaga,Spain?format=3" 2>/dev/null) # Fetch current weather
    
        # Check if the curl command was successful and if data was returned
        if [ $? -eq 0 ] && [ -n "$weather_data" ]; then
            echo -e "${GREEN}Current Weather: $weather_data${NC}"
        else
            echo -e "${RED}Unable to fetch weather data${NC}"
        fi
    }
    
    # Function to get news headlines
    get_news() {
        echo -e "${YELLOW}Getting latest news headlines...${NC}"
    
        curl -sL https://feeds.bbci.co.uk/news/rss.xml | xmlstarlet sel -t -m "//item" -v "title" -n | head -n 5
        # curl -sL https://feeds.bbci.co.uk/news/rss.xml: Fetches the RSS feed content silently
        # xmlstarlet sel -t -m "//item" -v "title" -n: Processes the XML content, selecting the titles of each ITEM in the feed.
        # head -n 5: Limits the output to the first five titles.
    }
    
    # Clear screen
    clear
    
    # Main dashboard display
    echo -e "${PURPLE}"
    figlet -f cybermedium "Info Dashboard" 2>/dev/null || echo "=== INFO DASHBOARD ==="
    echo -e "${NC}"
    
    # Display current time and date
    print_header "CURRENT TIME & DATE"
    echo -e "${GREEN}Current Time: $(date '+%H:%M:%S')${NC}"
    echo -e "${GREEN}Current Date: $(date '+%A, %B %d, %Y')${NC}"
    echo -e "${GREEN}$(cat /etc/timezone)${NC}"
    
    # Display calendar
    print_header "CALENDAR"
    echo -e "${BLUE}"
    cal -3 2>/dev/null || cal
    echo -e "${NC}"
    
    # Display weather
    print_header "WEATHER IN MALAGA"
    get_weather
    
    # Display news
    print_header "NEWS HEADLINES"
    get_news
    
    print_header "SYSTEM INFO"
    uname -a
    # Display resource and status of my website
    print_header "RESOURCE USAGE"
    echo -e "${YELLOW}Uptime: $(uptime -p)" # Print system uptime
    echo -e "CPU Load: $(cat /proc/loadavg | awk '{print $1", "$2", "$3}')" # Print CPU load averages
    echo -e "Memory: $(free -h | awk '/Mem/{print $3"/"$2}')" # Print memory usage
    echo -e "Disk: $(df -h / | awk 'NR==2{print $3"/"$2}')${NC}" # Print disk usage
    echo -e "Status of my website"
    if wget --spider -q https://justtothepoint.com/; then
        printf "Website is UP!\n"
    else
        printf "Website might be DOWN!\n"
    fi
    
  4. Save a file run_one.sh in this directory. It runs the dashboard once and exits.

    #!/bin/bash
    echo "Running dashboard once..."
    /app/dashboard.sh
    echo "Dashboard complete. Container will exit."
    
  5. Your directory structure should look like: ubuntu-dashboard/
    ├── Dockerfile
    ├── dashboard.sh
    ├── continuous_dashboard.sh
    └── run_once.sh \

  6. Build the image

    # Build the image
    docker build -t ubuntu-dashboard .
    # Docker aggressively caches build steps —even if you’ve changed files that should trigger a rebuild.
    # Add the --no-cache flag to force Docker to rebuild everything:
    docker build --no-cache -t ubuntu-dashboard .
    # After rebuilding, always run a new container
    docker run --rm -it ubuntu-dashboard
    
Bitcoin donation

JustToThePoint Copyright © 2011 - 2025 Anawim. ALL RIGHTS RESERVED. Bilingual e-books, articles, and videos to help your child and your entire family succeed, develop a healthy lifestyle, and have a lot of fun. Social Issues, Join us.

This website uses cookies to improve your navigation experience.
By continuing, you are consenting to our use of cookies, in accordance with our Cookies Policy and Website Terms and Conditions of use.