Docker Quickstart: Install, Build & Deploy Apps

Docker has become the backbone of modern DevOps and software delivery. It helps you build, ship, and run applications quickly and reliably. In this post, we’ll explore Docker installation, pulling and building images, running containers, using volumes, networks, Docker Compose, and finally scanning your images for security.
And yes — you’ll see real commands you can copy-paste!

Step 1: Install Docker on Ubuntu

Let’s get Docker up and running:

sudo apt update && sudo apt upgrade -y
sudo apt install docker.io -y

Next, add your user to the Docker group to avoid typing sudo every time and Confirm it works:

sudo usermod -aG docker $USER
newgrp docker
docker --version
docker ps

Step 2: Pull & Run a Docker Image

Docker Hub is a library of prebuilt images. For example, let’s run MySQL 5.7:

docker pull mysql:5.7
docker images

Run a container:

docker run -d -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.7

Enter the container:

docker exec -it <container-id> bash

Inside, log into MySQL and create a database (replace tushar with your name):

mysql -u root -p
CREATE DATABASE tushar;

Step 3: Build & Push Your Own Docker Image

Let’s create and publish a simple Java “Hello World” container.

Create Hello.java:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Then, create Dockerfile:

FROM openjdk:8
COPY Hello.java .
RUN javac Hello.java
CMD ["java", "Hello"]

Build and push:

docker build -t yourdockerhubusername/hello-java:latest .
docker login
docker push yourdockerhubusername/hello-java:latest

Step 4: Host a Flask App with Docker

Clone the sample app:

git clone https://github.com/LondheShubham153/flask-app-ecs
cd flask-app-ecs

Fix the version issue by editing requirements.txt (change flask=2.2.2 to flask).

Create Dockerfile:

FROM python:3.9
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]

Build and run on port 80:

docker build -t flask-app .
docker run -d -p 80:80 flask-app

Step 5: Use Volumes for Persistent Data

Avoid losing data when containers stop by mounting volumes.

Create a directory:

mkdir -p /home/ubuntu/volumes/mysql-data

Run MySQL with volume:

docker run -d -e MYSQL_ROOT_PASSWORD=my-secret-pw \
-v /home/ubuntu/volumes/mysql-data:/var/lib/mysql mysql:5.7

Now your databases stay even if you restart the container.

Step 6: Connect Containers with Docker Networks

Create a network:

docker network create mynetwork

Run database container inside network:

docker run -d --name mysql-db --network mynetwork \
-e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.7

Run Flask app in same network:

docker run -d -p 5000:5000 --network mynetwork \
-e MYSQL_HOST=mysql-db flask-app

Step 7: Use Docker Compose to Manage Multi-Container Apps

Docker Compose makes multi-container apps simple.

Create docker-compose.yml:

version: "3"
services:
  web:
    build: .
    ports:
      - "80:80"
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: my-secret-pw

Start everything:

docker-compose up -d

Step 8: Scan Your Images with Docker Scout

Check for vulnerabilities:

mkdir scout && cd scout
curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh
docker scout quickview yourdockerhubusername/hello-java:latest

Keep exploring. Continue reading on our blog.

YAML

Leave a Reply

Your email address will not be published. Required fields are marked *