Getting Started with Docker
Table of Contents
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)
Install and test
Install: From https://docker.github.io/engine/getstarted/linux_install_help/
curl -fsSL https://get.docker.com/ | sh
Verify installation:
docker version docker run hello-world
Check containers and images:
docker ps -a docker images
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>
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/
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
A real world example
Let's see how Docker is used by installing a B-Translator Client: http://info.btr.fs.al/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/