Getting Started with Docker

Reading time ~1 minute

Getting Started with Docker

Getting Started with Docker

1 What is Docker

Docker is an open platform for developing, shipping, and running applications. https://docker.github.io/engine/understanding-docker/

  • What it can be used for
    • Fast, consistent delivery of applications
    • Responsive deployment and scaling
    • Running more workloads on the same hardware
  • Its architecture
    • Daemon
    • CLI and API
    • Images
    • Containers
    • Registries (Docker Hub)

2 Install and test

3 Run a command in a docker container

  • Hello world:
    docker run ubuntu:14.04 /bin/echo 'Hello world'
    
  • An interactive container:
    docker run -t -i ubuntu:14.04 /bin/bash
    pwd
    ls
    exit
    
  • A daemonized hello world:
    docker run -d ubuntu:14.04 \
        /bin/sh -c "while true; do echo hello world; sleep 1; done"
    docker ps
    docker logs -f <name-of-container>
    docker stop <name-of-container>
    docker ps -a
    docker rm <name-of-container>
    

4 Create a web application container

  • Create a new container from ubuntu-upstart:
    docker run -d --name=webapp --hostname=example.org \
               -p 80:80 ubuntu-upstart:14.04
    
  • Update system packages of the container:
    alias docker-webapp-exec='docker exec -it webapp env TERM=xterm'
    docker-webapp-exec bash
    apt-get update
    apt-get -y upgrade
    
  • Install apache2 and mysql:
    apt-get install apache2 mysql-server php5 php5-mysql
    
  • Create a test app:
    cd /var/www/html/
    apt-get install vim
    vim index.php
    exit
    
  • Add this line on /etc/hosts.
    127.0.0.1 example.org
    
  • Try it in browser: http://example.org

5 Other docker commands

docker
docker inspect
docker inspect --help
docker inspect ubuntu-upstart:14.04
docker inspect webapp
docker inspect -f '{ { .NetworkSettings.IPAddress }}' webapp
docker top webapp

6 A real world example

Let's see how Docker is used by installing a B-Translator Client: http://info.btranslator.org/install.html

  • Get the image:
    docker search btranslator
    docker pull btranslator/btr_client:v3.0
    docker images
    
  • Create and start a container:
    docker create --name=btr_client --hostname=example.org \
        -p 443:443 --restart=always \
        btranslator/btr_client:v3.0
    docker ps
    docker ps -a
    docker start btr_client
    
  • Add this line on /etc/hosts.
    127.0.0.1 fr.example.org
    
  • Open in browser: https://fr.example.org

Date: 2016-10-18

Author: Dashamir Hoxha

Created: 2019-01-24 Thu 05:13

Emacs 25.1.1 (Org mode 8.2.10)

Validate

Ad-Hock Computer Lab

Ad-Hock Computer LabAd-Hock Computer LabTable of Contents1. Introduction2. There Is No Computer Lab2.1. Build a Wi-Fi LAN2.2. Install a V...… Continue reading

LTSP Scenarios

Published on December 21, 2018

LTSP Use Cases

Published on December 01, 2018