The installation of docker is out of scope of this tutorial, please refer the official document for the docker installation.
- Create the Images (Dockfiles) for development (mount project as volume) and deployment (integrate project)
- Keep persistent data separating from docker container
- Connect the docker containers instead of putting everything in the same container
> docker run -t -i ubuntu:14.04.2 /bin/bash
Run docker container with volume mounted by option -v
> docker run -t -i -v hostDir1:containerDir1 \
-v hostDir2:containerDir2 \
ubuntu:14.04.2 /bin/bash
> docker run -t -i --privileged -v /dev/bus/usb:/dev/bus/usb \
ubuntu /bin/bash
> docker run -t -i ubuntu:14.04.2 /bin/bash
> docker run -d -P myWebServer python app.py
-d
runs docker container in background (daemon)
- Get access:
> docker attach containerID
- Exit without halt
Ctrl+p
andCtrl+q
> docker stop containerID
> docker ps # verify the containerID
> docker commit -m "some mesg" containerID imageName:tag
! For Ubuntu/Debian, it is better to create a base system image with upgraded package
apt-get update && apt-get upgrade -y
# DOCKER-VERSION 1.6.0
# Erlang docker image
FROM ubuntubase:v1
MAINTAINER Jun HU <[email protected]>
# add the erlang repo and key
RUN echo "deb http://packages.erlang-solutions.com/ubuntu trusty contrib" >> /etc/apt/sources.list
RUN DEBIAN_FRONTEND=noninteractive apt-get install wget -y
RUN wget http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
RUN apt-key add erlang_solutions.asc
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
erlang \
rebar
> docker build -t "MyDockerImageName:tag" -f MyDockerfile # by default, the file name is Dockerfile
Docker images are the basis of containers.
A data volume is a specially-designated directory within one or more containers that bypasses the Union File System. Data volumes provide several useful features for persistent or shared data:
- Volumes are initialized when a container is created. If the container's base image contains data at the specified mount point, that data is copied into the new volume.
- Data volumes can be shared and reused among containers.
- Changes to a data volume are made directly.
- Changes to a data volume will not be included when you update an image.
- Data volumes persist even if the container itself is deleted.
Data volumes are designed to persist data, independent of the container's life cycle. Docker therefore never automatically delete volumes when you remove a container, nor will it "garbage collect" volumes that are no longer referenced by a container.
The official tutorial can be found here
> sudo usermod -aG docker yourusername
Set GRUB_CMDLINE_LINUX in /etc/default/grub
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
Update Grub and reboot
> sudo update-grub && sudo reboot
> wget -N https://get.docker.com/ | sh
> sudo restart network-manager $ sudo restart docker