Docker install and usage

In brief (and maybe a wrong way ^^ ):

- Docker helps us to create the containers (Linux and Windows containers).
- The container is similar to a virtual machines in VMware but it has a small size, image layers, linking and can be taken image snapshots.
- The container use the same kernel with the host machine (the machine which has installed Docker software) so it is more small size and good performance than virtual machine.



Update on November 2016

Linux

Install Docker on CentOS 7.

## Must be root

su root

## Edit your YUM

vi /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

## Install Docker
yum install docker-engine

## Store Docker files in opt
mkdir /opt/docker
mkdir /etc/systemd/system/docker.service.d/

vi /etc/systemd/system/docker.service.d/docker.conf
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --graph="/opt/docker/docker-data" --storage-driver=overlay

# Want to use proxy
vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/" "NO_PROXY=localhost,127.0.0.1"

systemctl daemon-reload
systemctl start docker

## Add user docker | password docker1 | group docker

useradd docker -g docker
passwd docker
docker1
usermod -aG docker docker
usermod -aG sshuser docker

chown -R docker /opt/docker

systemctl enable docker
# chkconfig docker on

# You might need to add Docker into the trusted zone
firewall-cmd --zone=trusted --permanent --add-interface=docker0

# Or add a por 2375 to trusted
firewall-cmd --zone=trusted --add-port=2375/tcp --permanent

firewall-cmd --reload

###############################################

su docker

docker run hello-world

systemctl status docker

Windows

Windows OS must be 64-bit operating system running Windows 7 or higher

Download Docker Toolbox for Windows
https://www.docker.com/products/docker-toolbox

Install the Docker Toolbox as: https://docs.docker.com/toolbox/toolbox_install_windows/

ATTENTION!
Look like you MUST install Docker Toolbox in the "C:\Program Files\Docker Toolbox"


If you have this issue.

docker info
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/info: open //./pipe/docker_engine: The system cannot find the file specified.

Here's my solution.

Open the "cmd"

cmd

"C:\Program Files\Git\bin\bash.exe" --login -i "C:\Program Files\Docker Toolbox\start.sh"

docker-machine rm -f default

export HTTP_PROXY=http://example.com:8080
export HTTPS_PROXY=https://example.com:8080
export NO_PROXY=192.168.*.*

# Look like you MUST install Docker Toolbox
# in the "C:\Program Files\Docker Toolbox"
# NOT RECOMMENDED !!!
# export MACHINE_STORAGE_PATH=F:\\docker

# I use the network 11.11.11.1 for my Docker instead of the Docker default 192.168.99.100
docker-machine create -d virtualbox
--virtualbox-hostonly-cidr "11.11.11.1/24"
--engine-env HTTP_PROXY=http://example.com:8080
--engine-env HTTPS_PROXY=https://example.com:8080
--engine-env NO_PROXY=192.168.*.*
default

yes | docker-machine regenerate-certs

docker-machine env default

eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default)

docker-machine restart default

docker run hello-world

When running

# Try the NGINX web server
docker run -d -p 8000:80 nginx

## On Windows, do not check the your localhost or 127.0.0.1

# Show Docker IP
docker-machine ip
# My case is 11.11.11.100

# Check the web server
curl $(docker-machine ip default):8000

Mounting Docker volume when running on Windows with Docker Toolbox

https://docs.docker.com/engine/tutorials/dockervolumes/

If you are using Docker Machine on Mac or Windows, your Docker Engine daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory. So, you can mount files or directories on OS X using.

On Windows, mount directories using:

docker run -v /c/Users/path/:/container_path

All other paths come from your virtual machine’s filesystem, so if you want to make some other host folder available for sharing, you need to do additional work. In the case of VirtualBox you need to make the host folder available as a shared folder in VirtualBox. Then, you can mount it using the Docker -v flag.

Customize the options used to start the Docker daemon persistent

Increase virtual memory vm.max_map_count in boot2docker (to run Elasticsearch 5.0)

# the default machine
docker-machine ssh default
sudo su
sysctl -w vm.max_map_count=262144
# it will be re-set after you re-boot your Windows host

# To make the setting persistent
sudo vi /var/lib/boot2docker/bootlocal.sh
# Add this line into the profile file
sysctl -w vm.max_map_count=262144

# Then re-start the Docker VM to check
chmod +x /var/lib/boot2docker/bootlocal.sh
exit
docker-machine restart
docker-machine ssh default "sysctl vm.max_map_count"

Can not create symbolic links on boot2docker

When runnin the GitLab CE image at "nguoianphu/docker-gitlab-ce" via docker-compose and mount the local volume, you might get this error:

https://gitlab.com/gitlab-org/gitlab-ce/issues/13734#note_17967573

Solution:

http://superuser.com/questions/124679/how-do-i-create-a-link-in-windows-7-home-premium-as-a-regular-user?answertab=votes#125981

To change the policies:

Launch secpol.msc via Start or Start → Run.

Open Security Settings → Local Policies → User Rights Assignment.

In the list, find the "Create symbolic links" item, which represents SeCreateSymbolicLinkPrivilege.
Double-click on the item and add yourself (or the whole Users group) to the list.

The changes will apply when you log out and log in again.

Clean up Docker

# This will remove the exited containers. The -v flag is there to remove any containers that will no longer be needed.
docker rm -v $(docker ps -a -q -f status=exited)

# Remove unwanted ‘dangling’ images.
docker rmi $(docker images -f "dangling=true" -q)

# Deleting the unwanted volumes
docker volume rm $(docker volume ls -qf dangling=true)



!!!OLD !!!!

Install Docker on Linux Centos

Centos 6

#### For Centos 6.6, I have some issues after install docker.
https://github.com/docker/docker/issues/14024

Workaround: download docker-io-1.6.2-3.el6.x86_64.rpm from
https://dl.fedoraproject.org/pub/epel/testing/6/x86_64/

Need download some libs for docker:

cd /etc/yum.repos.d
sudo wget http://www.hop5.in/yum/el6/hop5.repo

#### Install the RPM file and start docker on Centos 6

rpm -ivh docker-io-1.6.2-3.el6.x86_64.rpm

service docker start

If you have to use proxy, add this option into this file:

vi /etc/sysconfig/docker

export http_proxy=http://proxy.com:port

If your Proxy doesn't allow HTTPS, add this into that file also.

other_args="--insecure-registry docker.io"

Centos 7

## YUM

vi /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

## Install Docker
export HTTP_PROXY=http://proxy.com:port
export HTTPS_PROXY=http://proxy.com:port

yum install docker-engine

mkdir /opt/docker
mkdir /etc/systemd/system/docker.service.d/

vi /etc/systemd/system/docker.service.d/docker.conf
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --graph="/opt/docker/docker-data" --storage-driver=overlay

vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.com:port/" "NO_PROXY=localhost,127.0.0.1"

## Add user docker | password docker1 | group docker

useradd docker -g docker
passwd docker
docker1
usermod -aG docker docker
usermod -aG sshuser docker

chown -R docker /opt/docker

systemctl start docker
systemctl enable docker
# chkconfig docker on

su docker

docker run hello-world

systemctl status docker

Command only shows information about running containers
docker ps

Command to return the details of the last container started
docker ps -l

See stopped containers
docker ps -a

curl -L https://github.com/docker/compose/releases/download/1.8.0-rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose


Install Docker on Windows

Get the file boot2docker and run it.
https://docs.docker.com/installation/windows/

But use these steps instead of Docker website :)

### Open Windows CMD

### Add Git PATH (C:\Program Files (x86)\Git\bin
) into system PATH if you don't have Cygwin
SET PATH=%PATH%;C:\Program Files (x86)\Git\bin

bash

### If you have proxy

export http_proxy=http://proxy.com:port

### Assume that you're Administrator
### Go to
C:\Users\Administrator\.boot2docker
### Add the file profile with content:

# boot2docker profile filename: C:\Users\Administrator\.boot2docker\profile
Init = false
Verbose = false
Driver = "virtualbox"
Clobber = false
ForceUpgradeDownload = false
SSH = "ssh"
SSHGen = "ssh-keygen"
SSHKey = "C:\\Users\\Administrator\\\.ssh\\id_boot2docker"
VM = "boot2docker-vm"
Dir = "C:\\Users\\Administrator\\.boot2docker"
ISOURL = "https://api.github.com/repos/boot2docker/boot2docker/releases"
ISO = "C:\\Users\\Administrator\\.boot2docker\\boot2docker.iso"
DiskSize = 20000
Memory = 2048
CPUs = 4
SSHPort = 2022
DockerPort = 0
HostIP = "192.168.59.3"
DHCPIP = "192.168.59.99"
NetMask = [255, 255, 255, 0]
LowerIP = "192.168.59.103"
UpperIP = "192.168.59.254"
DHCPEnabled = true
Serial = false
SerialFile = "\\\\.\\pipe\\boot2docker-vm"
Waittime = 300
Retries = 75

### Create the dokcer virtual machine by VirtualBox
### Do it for the first time only

boot2docker init

### If you have proxy, you have to edit these files
### Do these steps for the first time only

boot2docker ssh

sudo vi /etc/systemconfig/boot2docker/profile

#### Add this line to the end of file
export https_proxy=http://proxy.com:port

### If your proxy don't allow https, add this into the docker start command
sudo vi /etc/init.d/docker

docker -d --insecure-registry docker.io

### Start the docker machine
### Do these steps whenever you start your Windows host machine and want to use docker

boot2docker up
eval "$(boot2docker shellinit)"
boot2docker ssh 'sudo /etc/init.d/docker restart'

export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH='C:\Users\Administrator\.boot2docker\certs\boot2docker-vm'
export DOCKER_TLS_VERIFY=1
export NO_PROXY=192.168.59.103

### Check if docker is OK

docker info

### And yes, run the hello world

docker run hello-world


Link Github and Docker Hub to create the automation build on cloud:

- Create a github repo. I.e: https://github.com/nguoianphu/docker-openssl.git

- Go to the repo Setting > Webhooks and Services > Services. Adding the Docker services and check Active.

- Go to Docker Hub webpage and link the Github repo into the automated build:

Create > Create Automated build
Choose Github or Bitbucket > Choose your repo

- Back to Github and create and commit a file name Dockerfile.

- Whenever we push a change into the Githup repo, Docker Hub will trigger a new build base on Dockerfile.

Now, we don't even need any local machine to build OpenSSL. Just using the cloud!

Loading