Alex Dai Playground

Posts match “ docker ” tag:

[Docker] cli

| Comments

# CentOS6
$ sudo yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
$ sudo yum install docker-io
# CentOS7
$ sudo yum install docker
$ sudo service docker start
$ sudo chkconfig docker on

$ sudo docker help
$ sudo docker help <command>

$ sudo docker pull ubuntu:14.04
$ sudo docker images
$ sudo docker run ubuntu:14.04 /bin/echo 123
$ sudo docker run -t -i ubuntu:14.04 /bin/bash

remove container
$ sudo docker rm <-f> container_id

remove all container
$ sudo docker ps -a | awk '{print $1}' | sudo xargs docker rm

remove image
$ sudo docker rmi ubuntu:14.04<image_id>

save image to local
$ sudo docker save -o ubuntu_14.04.tar ubuntu:14.04

load image form local

$ sudo docker load --input ubuntu_14.04.tar
or
$ sudo docker load < ubuntu_14.04.tar

顯示執行中的 container
$ sudo docker ps

顯示已停止的 container
$ sudo docker ps -a

守護態執行
$ sudo docker run -t -i -d ubuntu:14.04 /bin/bash

start container
$ sudo docker start container_id

進入執行中的 container
$ sudo docker exec -ti container_id bash

開啟名為 web 的 container 去掛載本機目錄 src/webapp (資料會同步)
$ sudo docker run -d --name web -v src/webapp:/opt/webapp imgage_id

新建container 使用 web 資料卷
$ sudo docker run -ti --volumes-from web --name test1 ubuntu:14.04 bash

開啟名為 web 的 container 以 joshhu/webdemo images 執行 web server,
記憶體 512m 、本機 8080 port 對應 container 80 port
$ sudo docker run -d --name web -m 512m -p 8080:80 joshhu/webdemo

移除所有容器
$ docker ps -q -a | xargs docker rm

移除 none images
$ docker rmi $(docker images -f "dangling=true" -q)
$ docker rmi $(docker images | grep “^<none>” | awk ‘{print $3}’)

查看容器名稱
$ docker inspect -f "{{ .Name }}" container_id
$ docker ps -l

統計 image 的 layer 數量 (上限127)
docker history IMAGE_NAME | wc -l

取得容器裡的 PATH 環境變數
docker inspect --format '{{ index (index .Config.Env) 1 }}' container_id

[Docker] GitLab Install

| Comments

OS

Ubuntu 14.04

Install docker

cmd
sudo apt-get purge docker.io
curl -s https://get.docker.com/ | sudo sh
sudo apt-get update
sudo apt-get install lxc-docker

Pull gitlab images

cmd
docker pull sameersbn/gitlab:latest
docker pull sameersbn/mysql:latest 
docker pull sameersbn/redis:latest

[Docker] version upgrade

| Comments

Add apt source

# add the new gpg key
$ apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

# edit your /etc/apt/sources.list.d/docker.list
$ vim /etc/apt/sources.list.d/docker.list

# remove the contents and replace with the following depending on your os and version:

# Ubuntu Trusty 
deb https://apt.dockerproject.org/repo ubuntu-trusty main

Upgrade to latest docker version

$ apt-get update

# remove the old
$ apt-get purge lxc-docker*

# install the new
$ apt-get install docker-engine

http://askubuntu.com/questions/472412/how-do-i-upgrade-docker

[Docker] without sudo

| Comments

Add the docker group

$ sudo groupadd docker

Add the connected user "${USER}" to the docker group

$ sudo gpasswd -a ${USER} docker

Restart the Docker daemon:

$ sudo service docker restart

Ubuntu 14.04 and up use docker.io instead

$ sudo service docker.io restart

Than

$ newgrp docker or log out/

[Docker] GitLab CI 設定

| Comments

已存在的 gitlab 容器

cmd
$ docker-compose ps
            Name                          Command               State              Ports                         
------------------------------------------------------------------------------------------------------
dockergitlab_gitlab-runner_1   /entrypoint run --user=git ...   Up                                                            
dockergitlab_gitlab_1          /sbin/entrypoint.sh app:start    Up      0.0.0.0:10022->22/tcp, 443/tcp, 0.0.0.0:10080->80/tcp 
dockergitlab_postgresql_1      /sbin/entrypoint.sh              Up      5432/tcp                                              
dockergitlab_redis_1           /sbin/entrypoint.sh              Up      6379/tcp     

設定 註冊 gitlab-runner

cmd
$ docker exec -it dockergitlab_gitlab-runner_1 gitlab-runner register

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
$ http://gitlab.alex.dai.com:10080/ci

Please enter the gitlab-ci token for this runner
$ a60b0ac5e158ca0da75a348dd911ab

Please enter the gitlab-ci description for this runner
$ node-4.1.1

Please enter the gitlab-ci tag for this runner
$ node-4.1.1

Please enter the executor: docker, docker-ssh, ssh, shell, parallels:
$ docker

Please enter the Docker image (eg. ruby:2.1):
$ node:4.1.1

If you want to enable mysql please enter version (X.Y) or enter latest?

If you want to enable postgres please enter version (X.Y) or enter latest?

If you want to enable redis please enter version (X.Y) or enter latest?

If you want to enable mongo please enter version (X.Y) or enter latest?

Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!


結果



P.S: 我在一開始無法正常 bulid

因為我是 win10 所以用 virtualbox 裝 Ubuntu 再用 ssh 登入,且為了 gitlab 能在本地端使用 Google OAuth 登入,因此修改了本地 DNS 設定。

C:\Windows\System32\drivers\etc\hosts
192.168.56.1       gitlab.alex.dai.com

192.168.56.1 是本地 virtualbox 的網卡ip ,我是對應到 10.0.2.15 這個 virtualbox 內部 ip。

所以關於 host 設定不能用 gitlab.alex.dai.com 這個自己設定的網域,否則 gitlab runner 會無法送出請求到 gitlab。

修正如下:

docker-compose.yml
  gitlab:

  ...

  ...

- GITLAB_HOST=192.168.56.1
cmd docker exec -it dockergitlab_gitlab-runner_1 gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
$ http://192.168.56.1:10080/ci

收工!!!

我覺得還是直接在 Linux 的環境下操作比較沒問題,原本是要在 AWS EC2 上操作的,想不到試用期的免費主機的記憶體只有1G(實際可用700多MB),導致常常出現 502 error、CPU 飆高,gitlab 最後直接死掉無法瀏覽..

References

[Docker for Windows] Network timed out while trying to connect to ...

| Comments

問題

$ docker pull images....

Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/nginx/images. You may want to check your internet connection or if you are behind a proxy.

解決:

  • Disabled IPv6 on DockerNAT adapter.

  • Set IPv4 DNS to 8.8.8.8 / 8.8.4.4

  • Reboot PC. Stalled. Forced shutdown. Restarted.

System info

  • Docker 1.11.2-beta15 build:4450
  • Windows 10 Pro Insider 1511 Build 10586.420

https://forums.docker.com/t/docker-pull-wont-work/8506/42

[AWS] amazon linux insatll docker & docker-compose

| Comments

install docker

$ sudo yum update
$ sudo yum install -y docker
$ sudo usermod -aG docker ec2-user
$ sudo service docker start

install docker-compose

$ sudo su

$ curl -L "https://github.com/docker/compose/releases/download/1.8.0/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose

$ chmod +x /usr/local/bin/docker-compose

$ exit

$ docker-compose --version