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 '' 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: 2016-10-28 Fri 05:33

Moodle For Every School

Moodle For Every SchoolMoodle For Every SchoolTable of Contents1. Abstract2. Introduction3. Installing Moodle4. Moodle as a Service5. Ins...… Continue reading

Building SSH Tunnels

Published on March 25, 2017