顯示具有 Docker 標籤的文章。 顯示所有文章
顯示具有 Docker 標籤的文章。 顯示所有文章

2022年3月7日 星期一

Running Docker on macOS M1 Issue

macOS Version - sw_vers

ProductName:    macOS
ProductVersion:    12.2.1
BuildVersion:    21D62

macOS detail Version - system_profiler SPSoftwareDataType

Software:

    System Software Overview:

      System Version: macOS 12.2.1 (21D62)

      Kernel Version: Darwin 21.3.0

      Boot Volume: Macintosh HD

      Boot Mode: Normal

      Computer Name: ooo的MacBook Pro

      User Name: ooo (Nobody)

      Secure Virtual Memory: Enabled

      System Integrity Protection: Enabled

      Time since boot: 1 day 13:57

Issue: qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

Just need to add --platform=linux/amd64 into Dockerfile

From --platform=linux/amd64 ubuntu:20.04

Reference:


Thanks to my colleague - Alan Chen.

2018年2月21日 星期三

What is difference ARG and ENV in Dockerfile

LAB 1:

  • Dockerfile
請注意,這邊用的是 ENV PHPVERSION 5
FROM alpine:latest
LABEL description="This example Dockerfile installs Apache & PHP."
ENV PHPVERSION 5
RUN apk add --update apache2 php${PHPVERSION}-apache2 php${PHPVERSION} && \
    rm -rf /var/cache/apk/* && \
    mkdir /run/apache2/ && \
    rm -rf /var/www/localhost/htdocs/index.html && \
    echo "" > /var/www/localhost/htdocs/index.php && \
    chmod 755 /var/www/localhost/htdocs/index.php
EXPOSE 80/tcp
ENTRYPOINT ["httpd"]
CMD ["-D", "FOREGROUND"]
接著我們把它給 build 成 docker image
# docker build --tag local/apache-php:5 .
再來我們來做個實驗,在 docker run 時,使用 --env "PHPVERSION=7" 會不會跑成 PHP7
# docker container run --env "PHPVERSION=7" -p 8080:80 --name apache-php7 local/apache-php:5
請先確認 docker container 的狀態為 Up 即可
# docker container list
請打開 Browser 輸入 http://IP-ADDRESS:8080,確認 PHP INFO

接著我們在進入到 docker container 裡面去確認 PHPVERSION 這個變數有沒有改變,請另開一個 terminal 來執行
# docker exec -it apache-php7 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8ab899f69969
TERM=xterm
PHPVERSION=7
HOME=/root
唔!很明顯有 PHPVERSION=7 ,但為什麼網頁上的 PHP VERSION 卻還是 5 哩!
這是因為在 docker build 的時候,已經先指定好版本了,並且已經製作出 docker image 了,所以沒辦法去變更 PHPVERSION=5。
LAB 2:
  • Dockerfile
請注意,這邊預設用的是 ARG buildtime_PHPVERSION=5
FROM alpine:latest
LABEL description="This example Dockerfile installs Apache & PHP."
ARG buildtime_PHPVERSION=5
ENV env_var_name=$buildtime_PHPVERSION
RUN apk add --update apache2 php${buildtime_PHPVERSION}-apache2 php${buildtime_PHPVERSION} && \
    rm -rf /var/cache/apk/* && \
    mkdir /run/apache2/ && \
    rm -rf /var/www/localhost/htdocs/index.html && \
    echo "" > /var/www/localhost/htdocs/index.php && \
    chmod 755 /var/www/localhost/htdocs/index.php
EXPOSE 80/tcp
ENTRYPOINT ["httpd"]
CMD ["-D", "FOREGROUND"]
接著我們把它給 build 成 docker image,並命名為 local/apache-php:5
# docker build --tag local/apache-php:5 .
使用 --build-arg 這個參數,再 build 一個 docker image,並命名為 local/apache-php:7
# docker build --build-arg buildtime_PHPVERSION=7 --tag local/apache-php:7 .
請觀察 docker images
# docker images
請同時啟動 local/apache-php:5 & local/apache-php:7,並觀察兩個 docker container 的 PHP VERSION
# docker container run -d -p 9090:80 --name apache-php5 local/apache-php:5
# docker container run -d -p 8080:80 --name apache-php7 local/apache-php:7
請確認 docker container 狀態為 UP
# docker container list
CONTAINER ID        IMAGE                COMMAND                 CREATED             STATUS              PORTS                  NAMES
278b3a6d165b        local/apache-php:5   "httpd -D FOREGROUND"   11 minutes ago      Up 11 minutes       0.0.0.0:9090->80/tcp   apache-php5
4f57218453c9        local/apache-php:7   "httpd -D FOREGROUND"   12 minutes ago      Up 12 minutes       0.0.0.0:8080->80/tcp   apache-php7
請打開 Browser 分別輸入 http://IP-ADDRESS:8080 & http://IP-ADDRESS:9090



明顯可以看出,有不同的 PHP VERSION
接著分別確認一下,這二個 docker container 的 ENV 是什麼
# docker exec -it apache-php7 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=4f57218453c9
TERM=xterm
env_var_name=7
HOME=/root
# docker exec -it apache-php5 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=278b3a6d165b
TERM=xterm
env_var_name=5
HOME=/root

詳細原因可以參考下面這張圖



Reference:

2016年5月18日 星期三

DC/OS on CentOS

Update system packages 

$ sudo yum udate -y && sudo yum upgrade -y
Please check your kernel version
$ uname -r
3.10.0-327.10.1.el7.x86_64
Docker requirements
  • Docker 1.7 or greater must be installed on all bootstrap and cluster nodes.
Docker recommendations
  • Docker 1.9 or greater is recommended for stability reasons.
  • Do not use Docker devicemapper storage driver in loop-lvm mode.
  • Prefer OverlayFS or devicemapper in direct-lvm mode when choosing a production storage driver.
  • Manage Docker on CentOS with systemd.
  • Run Docker commands as the root user (with sudo) or as a user in the docker user group.
Setting Overlay script for CentOS7
#!/bin/bash
 
#####
# Basic tool
#####
 
yum -y install curl git tig tree vim wget
yum -y groupinstall "Development Tools"
 
#####
# Docker Repo
#####
 
DOCKER_REPO="/etc/yum.repos.d/docker.repo"
 
if [ -f ${DOCKER_REPO} ]; then
    echo -e "\033[0;33;40mDocker Repo exist\033[0m"
    echo -e "\033[0;36;40mInstall Docker Engine\033[0m"
    yum install -y docker-engine
    echo -e "\033[0;32;40mdone\033[0m"
else
    echo -e "\033[0;36;40mSetting Docker Repo\033[0m"
    tee ${DOCKER_REPO} <<- -e="" -y="" 2="" baseurl="https://yum.dockerproject.org/repo/main/centos/7/" docker-engine="" docker="" dockerrepo="" echo="" enable="" enabled="1" engine="" eof="" fi="" gpgcheck="1" gpgkey="https://yum.dockerproject.org/gpg" grep="" install="" lsmod="" m="" mdone="" minstall="" module="" name="Docker" overlay="" repository="" sleep="" yum="">> /dev/null
check_overlay=$?
 
if [ ${check_overlay} = 0 ]; then
    echo -e "\033[0;33;40mAlready Enabled overlay module\033[0m"
else
    echo -e "\033[0;36;40mEnable overlay module\033[0m"
    modprobe overlay
    echo -e "\033[0;32;40mdone\033[0m"
fi
 
sleep 2
#####
# Setting Disk and mount
####
 
HDD_DEVICE="`cat /var/log/messages | grep 'unknown partition table' | awk '{print $6}' | cut -d: -f1 | head -n 1`"
OVERLAY_DIR="/var/lib/docker/overlay"
 
if [ -b /dev/${HDD_DEVICE}1 ]; then
    echo -e "\033[0;33;40m${HDD_DEVICE}1 exist\033[0m"
else
    echo -e "\033[0;36;40mFormate Disk\033[0m"
    echo "n
p
1
 
 
w
"|fdisk /dev/${HDD_DEVICE}; mkfs.ext4 /dev/${HDD_DEVICE}1
    echo -e "\033[0;32;40mdone\033[0m"
fi
 
sleep 2
 
if [ -d ${OVERLAY_DIR} ]; then
    echo -e "\033[0;33;40m${OVERLAY_DIR} exist\033[0m"
else
    echo -e "\033[0;36;40mCreating ${OVERLAY_DIR} directoy\033[0m"
    mkdir -p ${OVERLAY_DIR}
    echo -e "\033[0;32;40mdone\033[0m"
fi
 
sleep 2
 
cat /etc/fstab | grep 'overlay' >> /dev/null
check_uuid=$?
HDD_UUID_1="`blkid  /dev/${HDD_DEVICE}1 | awk '{print $2}' | sed 's/\"//g'`"
 
if [ ${check_uuid} = 0 ]; then
    echo -e "\033[0;33;40mfstab OK\033[0m"
else
    echo -e "\033[0;36;40mSetting fstab\033[0m"
    echo -n "${HDD_UUID_1}    ${OVERLAY_DIR}  ext4 defaults 0 2" >> /etc/fstab
    mount -a
    echo -e "\033[0;32;40mdone\033[0m"
fi
 
sleep 2
#####
# Setting Docker Engine
####
 
DOCKER_SERVICE="/usr/lib/systemd/system/docker.service"
 
grep '\-\-storage-driver=overlay' ${DOCKER_SERVICE} >> /dev/null
check_storage_driver=$?
 
if [ ${check_storage_driver} = 0 -a -f ${DOCKER_SERVICE} ]; then
  echo -e "\033[0;33;40mDocker Storage nothing to do\033[0m"
else
  echo -e "\033[0;36;40mSetting docker storage\033[0m"
  sed 12d -i ${DOCKER_SERVICE}
  sed "11 aExecStart=/usr/bin/docker daemon --storage-driver=overlay -H fd://" -i ${DOCKER_SERVICE} >> /dev/null
  echo -e "\033[0;32;40mdone\033[0m"
fi
 
#####
# Enable Docker
#####
 
systemctl daemon-reload
systemctl start docker
On CentOS 7, firewalld must be stopped and disabled.
$ sudo systemctl stop firewalld && sudo systemctl disable firewalld
Data compression (advanced installer),to install these utilities on CentOS7 and RHEL7:
$ sudo yum install -y tar xz unzip curl ipset
Cluster permissions (advanced installer)
On each of your cluster nodes, use the following command to:
  • Disable SELinux or set it to permissive mode.
  • Add nogroup to each of your Mesos masters and agents.
  • Disable IPV6.
$ sudo sed -i s/SELINUX=enforcing/SELINUX=permissive/g /etc/selinux/config &&
  sudo groupadd nogroup &&
  sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 &&
  sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 &&
  sudo reboot
  • Download the DC/OS installer
curl -O https://downloads.dcos.io/dcos/EarlyAccess/dcos_generate_config.sh
  • Create a directory named genconf on your bootstrap each node.
sudo mkdir -p genconf && cd genconf
  • Create a ip-detect script
#!/usr/bin/env bash
set -o nounset -o errexit
export PATH=/usr/sbin:/usr/bin:$PATH
echo $(ip addr show eth0 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
  • Create config.yaml. for exammple
---
agent_list:
- 
- 
- 
bootstrap_url: file:///opt/dcos_install_tmp
cluster_name: DCOS
exhibitor_storage_backend: static
ip_detect_filename: /genconf/ip-detect
master_discovery: static
master_list:
- 
- 
- 
process_timeout: 10000
resolvers:
- 8.8.8.8
ssh_port: 22
ssh_user: 
  • Copy your private SSH key to genconf/ssh_key
$ cp  genconf/ssh_key && chmod 0600 genconf/ssh_key
Now you genconf will be like this and copy to each node
genconf/
├── config.yaml
├── ip-detect
└── ssh_key
$ scp -rp genconf username@:
Check help
$ sudo bash dcos_generate_config.sh --help
Running mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
usage:
Install DC/OS
 
dcos_installer [-h] [-f LOG_FILE] [--hash-password HASH_PASSWORD] [-v]
[--web | --genconf | --preflight | --deploy | --postflight | --uninstall | --validate-config | --test]
 
Environment Settings:
 
  PORT                  Set the :port to run the web UI
  CHANNEL_NAME          ADVANCED - Set build channel name
  BOOTSTRAP_ID          ADVANCED - Set bootstrap ID for build
 
optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Verbose log output (DEBUG).
  --offline             Do not install preflight prerequisites on CentOS7,
                        RHEL7 in web mode
  --web                 Run the web interface.
  --genconf             Execute the configuration generation (genconf).
  --preflight           Execute the preflight checks on a series of nodes.
  --install-prereqs     Install preflight prerequisites. Works only on CentOS7
                        and RHEL7.
  --deploy              Execute a deploy.
  --postflight          Execute postflight checks on a series of nodes.
  --uninstall           Execute uninstall on target hosts.
  --validate-config     Validate the configuration in config.yaml
  --test                Performs tests on the dcos_installer application
  • Run this command for each master and node.
sudo bash dcos_generate_config.sh --install-prereqs
  • Run docker nginx for download install dcos_install.sh on master, and other node just download dcos_install.sh
sudo bash dcos_generate_config.sh
sudo docker run -d -p :80 -v $PWD/genconf/serve:/usr/share/nginx/html:ro nginx
Create /tmp/dcos directory and download dcos_install.sh
mkdir -p /tmp/dcos && cd /tmp/dcos
curl -O http://:/dcos_install.sh
sudo bash dcos_install.sh 
role must be master or slave
Now You can check
ZooKeeper http://IP:8181/exhibitor/v1/ui/index.html
Mesos http://IP:5050
DC/OShttp://IP

2015年11月25日 星期三

Docker install on Ubuntu


OS: Ubuntu 14.04(LTS)

Add GPG Key

sudo apt-key adv — keyserver hkp://p80.pool.sks-keyservers.net:80 — recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Create Docker Repo

echo “deb https://apt.dockerproject.org/repo ubuntu-trusty main” > /etc/apt/sources.list.d/docker.list

Update the apt package index

apt-get update

Purge the old repo if it exists

apt-get purge lxc-docker
Actuaully, you can skip this step, if your system is new installed, lxc-docker this package isn’t exist.

Verify that apt is pulling from the right repository

apt-cache policy docker-engine

Install Docker

apt-get install docker-engine && sudo shutdown -r now
Now you can play docker now…enjoy it~!!

Reference